mirror of
https://github.com/actions/configure-pages.git
synced 2026-03-30 10:04:52 +00:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5a3e1159e | ||
|
|
a069fede0c | ||
|
|
2f460cfbe0 | ||
|
|
e5c1ee9f14 | ||
|
|
7fea7010df | ||
|
|
34521f23a5 | ||
|
|
d84b27279d | ||
|
|
5650def507 | ||
|
|
0c2178e929 | ||
|
|
948e60fb96 | ||
|
|
1305a1ba92 | ||
|
|
b94e9adb36 | ||
|
|
fc8c2c4e6e | ||
|
|
e978eba337 | ||
|
|
343cb08233 | ||
|
|
f87a94c875 | ||
|
|
7eb40247a7 | ||
|
|
86f141f32d | ||
|
|
76b6a8292e | ||
|
|
8e221f24db | ||
|
|
d897860efd | ||
|
|
24270f0cca | ||
|
|
0c3c14948a | ||
|
|
b0c19d0de9 | ||
|
|
51323db177 | ||
|
|
3d9811d6e2 | ||
|
|
9c3b6344a2 | ||
|
|
97fb35057c | ||
|
|
c917d1c3cd | ||
|
|
ffa824f004 | ||
|
|
d4a76d1ee1 | ||
|
|
bd8a5da49f | ||
|
|
5cb77813a2 | ||
|
|
2094727a1b | ||
|
|
d875fa8dc1 | ||
|
|
67f329fcfd |
2
.github/workflows/draft-release.yml
vendored
2
.github/workflows/draft-release.yml
vendored
@@ -11,7 +11,7 @@ jobs:
|
|||||||
draft-release:
|
draft-release:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- uses: release-drafter/release-drafter@v5
|
- uses: release-drafter/release-drafter@v5
|
||||||
env:
|
env:
|
||||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|||||||
2
.github/workflows/release.yml
vendored
2
.github/workflows/release.yml
vendored
@@ -24,7 +24,7 @@ jobs:
|
|||||||
steps:
|
steps:
|
||||||
- name: Update the ${{ env.TAG_NAME }} tag
|
- name: Update the ${{ env.TAG_NAME }} tag
|
||||||
id: update-major-tag
|
id: update-major-tag
|
||||||
uses: actions/publish-action@v0.1.0
|
uses: actions/publish-action@v0.2.1
|
||||||
with:
|
with:
|
||||||
source-tag: ${{ env.TAG_NAME }}
|
source-tag: ${{ env.TAG_NAME }}
|
||||||
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
slack-webhook: ${{ secrets.SLACK_WEBHOOK }}
|
||||||
|
|||||||
287
dist/index.js
vendored
287
dist/index.js
vendored
@@ -140,7 +140,6 @@ const file_command_1 = __nccwpck_require__(717);
|
|||||||
const utils_1 = __nccwpck_require__(5278);
|
const utils_1 = __nccwpck_require__(5278);
|
||||||
const os = __importStar(__nccwpck_require__(2037));
|
const os = __importStar(__nccwpck_require__(2037));
|
||||||
const path = __importStar(__nccwpck_require__(1017));
|
const path = __importStar(__nccwpck_require__(1017));
|
||||||
const uuid_1 = __nccwpck_require__(5840);
|
|
||||||
const oidc_utils_1 = __nccwpck_require__(8041);
|
const oidc_utils_1 = __nccwpck_require__(8041);
|
||||||
/**
|
/**
|
||||||
* The code to exit an action
|
* The code to exit an action
|
||||||
@@ -170,20 +169,9 @@ function exportVariable(name, val) {
|
|||||||
process.env[name] = convertedVal;
|
process.env[name] = convertedVal;
|
||||||
const filePath = process.env['GITHUB_ENV'] || '';
|
const filePath = process.env['GITHUB_ENV'] || '';
|
||||||
if (filePath) {
|
if (filePath) {
|
||||||
const delimiter = `ghadelimiter_${uuid_1.v4()}`;
|
return file_command_1.issueFileCommand('ENV', file_command_1.prepareKeyValueMessage(name, val));
|
||||||
// These should realistically never happen, but just in case someone finds a way to exploit uuid generation let's not allow keys or values that contain the delimiter.
|
|
||||||
if (name.includes(delimiter)) {
|
|
||||||
throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`);
|
|
||||||
}
|
}
|
||||||
if (convertedVal.includes(delimiter)) {
|
|
||||||
throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`);
|
|
||||||
}
|
|
||||||
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
|
|
||||||
file_command_1.issueCommand('ENV', commandValue);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
command_1.issueCommand('set-env', { name }, convertedVal);
|
command_1.issueCommand('set-env', { name }, convertedVal);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
exports.exportVariable = exportVariable;
|
exports.exportVariable = exportVariable;
|
||||||
/**
|
/**
|
||||||
@@ -201,7 +189,7 @@ exports.setSecret = setSecret;
|
|||||||
function addPath(inputPath) {
|
function addPath(inputPath) {
|
||||||
const filePath = process.env['GITHUB_PATH'] || '';
|
const filePath = process.env['GITHUB_PATH'] || '';
|
||||||
if (filePath) {
|
if (filePath) {
|
||||||
file_command_1.issueCommand('PATH', inputPath);
|
file_command_1.issueFileCommand('PATH', inputPath);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
command_1.issueCommand('add-path', {}, inputPath);
|
command_1.issueCommand('add-path', {}, inputPath);
|
||||||
@@ -241,7 +229,10 @@ function getMultilineInput(name, options) {
|
|||||||
const inputs = getInput(name, options)
|
const inputs = getInput(name, options)
|
||||||
.split('\n')
|
.split('\n')
|
||||||
.filter(x => x !== '');
|
.filter(x => x !== '');
|
||||||
|
if (options && options.trimWhitespace === false) {
|
||||||
return inputs;
|
return inputs;
|
||||||
|
}
|
||||||
|
return inputs.map(input => input.trim());
|
||||||
}
|
}
|
||||||
exports.getMultilineInput = getMultilineInput;
|
exports.getMultilineInput = getMultilineInput;
|
||||||
/**
|
/**
|
||||||
@@ -274,8 +265,12 @@ exports.getBooleanInput = getBooleanInput;
|
|||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
function setOutput(name, value) {
|
function setOutput(name, value) {
|
||||||
|
const filePath = process.env['GITHUB_OUTPUT'] || '';
|
||||||
|
if (filePath) {
|
||||||
|
return file_command_1.issueFileCommand('OUTPUT', file_command_1.prepareKeyValueMessage(name, value));
|
||||||
|
}
|
||||||
process.stdout.write(os.EOL);
|
process.stdout.write(os.EOL);
|
||||||
command_1.issueCommand('set-output', { name }, value);
|
command_1.issueCommand('set-output', { name }, utils_1.toCommandValue(value));
|
||||||
}
|
}
|
||||||
exports.setOutput = setOutput;
|
exports.setOutput = setOutput;
|
||||||
/**
|
/**
|
||||||
@@ -404,7 +399,11 @@ exports.group = group;
|
|||||||
*/
|
*/
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
function saveState(name, value) {
|
function saveState(name, value) {
|
||||||
command_1.issueCommand('save-state', { name }, value);
|
const filePath = process.env['GITHUB_STATE'] || '';
|
||||||
|
if (filePath) {
|
||||||
|
return file_command_1.issueFileCommand('STATE', file_command_1.prepareKeyValueMessage(name, value));
|
||||||
|
}
|
||||||
|
command_1.issueCommand('save-state', { name }, utils_1.toCommandValue(value));
|
||||||
}
|
}
|
||||||
exports.saveState = saveState;
|
exports.saveState = saveState;
|
||||||
/**
|
/**
|
||||||
@@ -470,13 +469,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.issueCommand = void 0;
|
exports.prepareKeyValueMessage = exports.issueFileCommand = void 0;
|
||||||
// We use any as a valid input type
|
// We use any as a valid input type
|
||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
const fs = __importStar(__nccwpck_require__(7147));
|
const fs = __importStar(__nccwpck_require__(7147));
|
||||||
const os = __importStar(__nccwpck_require__(2037));
|
const os = __importStar(__nccwpck_require__(2037));
|
||||||
|
const uuid_1 = __nccwpck_require__(5840);
|
||||||
const utils_1 = __nccwpck_require__(5278);
|
const utils_1 = __nccwpck_require__(5278);
|
||||||
function issueCommand(command, message) {
|
function issueFileCommand(command, message) {
|
||||||
const filePath = process.env[`GITHUB_${command}`];
|
const filePath = process.env[`GITHUB_${command}`];
|
||||||
if (!filePath) {
|
if (!filePath) {
|
||||||
throw new Error(`Unable to find environment variable for file command ${command}`);
|
throw new Error(`Unable to find environment variable for file command ${command}`);
|
||||||
@@ -488,7 +488,22 @@ function issueCommand(command, message) {
|
|||||||
encoding: 'utf8'
|
encoding: 'utf8'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
exports.issueCommand = issueCommand;
|
exports.issueFileCommand = issueFileCommand;
|
||||||
|
function prepareKeyValueMessage(key, value) {
|
||||||
|
const delimiter = `ghadelimiter_${uuid_1.v4()}`;
|
||||||
|
const convertedValue = utils_1.toCommandValue(value);
|
||||||
|
// These should realistically never happen, but just in case someone finds a
|
||||||
|
// way to exploit uuid generation let's not allow keys or values that contain
|
||||||
|
// the delimiter.
|
||||||
|
if (key.includes(delimiter)) {
|
||||||
|
throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`);
|
||||||
|
}
|
||||||
|
if (convertedValue.includes(delimiter)) {
|
||||||
|
throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`);
|
||||||
|
}
|
||||||
|
return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}`;
|
||||||
|
}
|
||||||
|
exports.prepareKeyValueMessage = prepareKeyValueMessage;
|
||||||
//# sourceMappingURL=file-command.js.map
|
//# sourceMappingURL=file-command.js.map
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@@ -15256,7 +15271,7 @@ Pages's path based routing (and work).
|
|||||||
|
|
||||||
Supported configuration initializations:
|
Supported configuration initializations:
|
||||||
|
|
||||||
(1) Default export:
|
(1) Direct default export:
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
// configuration object here
|
// configuration object here
|
||||||
@@ -15268,19 +15283,69 @@ Supported configuration initializations:
|
|||||||
// configuration object here
|
// configuration object here
|
||||||
}
|
}
|
||||||
|
|
||||||
(3) Indirect module export:
|
(3) Indirect default export:
|
||||||
|
|
||||||
const config = // configuration object here
|
const config = {
|
||||||
|
// configuration object here
|
||||||
|
}
|
||||||
|
export default config
|
||||||
|
|
||||||
|
(4) Indirect module export:
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
// configuration object here
|
||||||
|
}
|
||||||
module.exports = config
|
module.exports = config
|
||||||
|
|
||||||
|
(5) Direct default export with wrapping call:
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
// configuration object here
|
||||||
|
})
|
||||||
|
|
||||||
|
(6) Direct module export with wrapping call:
|
||||||
|
|
||||||
|
module.exports = defineConfig({
|
||||||
|
// configuration object here
|
||||||
|
})
|
||||||
|
|
||||||
|
(7) Indirect default export with wrapping call at the definition:
|
||||||
|
|
||||||
|
const config = defineConfig({
|
||||||
|
// configuration object here
|
||||||
|
})
|
||||||
|
export default config
|
||||||
|
|
||||||
|
(8) Indirect default export with wrapping call at the export:
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
// configuration object here
|
||||||
|
}
|
||||||
|
export default defineConfig(config)
|
||||||
|
|
||||||
|
(9) Indirect module export with wrapping call at the definition:
|
||||||
|
|
||||||
|
const config = defineConfig({
|
||||||
|
// configuration object here
|
||||||
|
})
|
||||||
|
module.exports = config
|
||||||
|
|
||||||
|
(10) Indirect module export with wrapping call at the export:
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
// configuration object here
|
||||||
|
}
|
||||||
|
module.exports = defineConfig(config)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class ConfigParser {
|
class ConfigParser {
|
||||||
// Ctor
|
// Ctor
|
||||||
// - configurationFile: path to the configuration file
|
// - configurationFile: path to the configuration file
|
||||||
// - blankConfigurationFile: a blank configuration file to use if non was previously found
|
// - blankConfigurationFile: a blank configuration file to use if non was previously found
|
||||||
constructor({ configurationFile, blankConfigurationFile, properties }) {
|
constructor({ configurationFile, blankConfigurationFile, allowWrappingCall = false, properties }) {
|
||||||
// Save field
|
// Save field
|
||||||
this.configurationFile = configurationFile
|
this.configurationFile = configurationFile
|
||||||
|
this.allowWrappingCall = allowWrappingCall === true
|
||||||
this.properties = properties
|
this.properties = properties
|
||||||
|
|
||||||
// If the configuration file does not exist, initialize it with the blank configuration file
|
// If the configuration file does not exist, initialize it with the blank configuration file
|
||||||
@@ -15296,12 +15361,43 @@ class ConfigParser {
|
|||||||
this.configuration = fs.readFileSync(this.configurationFile, 'utf8')
|
this.configuration = fs.readFileSync(this.configurationFile, 'utf8')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findTopLevelVariableDeclarator(ast, identifierName) {
|
||||||
|
let targetDeclarator
|
||||||
|
ast.body.find(
|
||||||
|
node =>
|
||||||
|
node.type === 'VariableDeclaration' &&
|
||||||
|
node.declarations &&
|
||||||
|
node.declarations.length > 0 &&
|
||||||
|
node.declarations.find(declarator => {
|
||||||
|
if (
|
||||||
|
declarator.type === 'VariableDeclarator' &&
|
||||||
|
declarator.id &&
|
||||||
|
declarator.id.type === 'Identifier' &&
|
||||||
|
declarator.id.name === identifierName
|
||||||
|
) {
|
||||||
|
targetDeclarator = declarator
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
return targetDeclarator
|
||||||
|
}
|
||||||
|
|
||||||
// Find the configuration object in an AST.
|
// Find the configuration object in an AST.
|
||||||
// Look for a default export, a direct module export or an indirect module
|
// Look for, in order:
|
||||||
// export (in that order).
|
// - a direct default export
|
||||||
|
// - a direct default export with a wrapping call
|
||||||
|
// - an indirect default export
|
||||||
|
// - an indirect default export with a wrapping call at the definition
|
||||||
|
// - an indirect default export with a wrapping call at the export
|
||||||
|
// - a direct module export
|
||||||
|
// - a direct module export with a wrapping call
|
||||||
|
// - an indirect module export
|
||||||
|
// - an indirect module export with a wrapping call at the definition
|
||||||
|
// - an indirect module export with a wrapping call at the export
|
||||||
//
|
//
|
||||||
// Return the configuration object or null.
|
// Return the configuration object or null.
|
||||||
findConfigurationObject(ast) {
|
findConfigurationObject(ast, allowWrappingCall = false) {
|
||||||
// Try to find a default export
|
// Try to find a default export
|
||||||
var defaultExport = ast.body.find(node => node.type === 'ExportDefaultDeclaration')
|
var defaultExport = ast.body.find(node => node.type === 'ExportDefaultDeclaration')
|
||||||
|
|
||||||
@@ -15311,21 +15407,61 @@ class ConfigParser {
|
|||||||
return defaultExport.declaration
|
return defaultExport.declaration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Direct default export with a wrapping call
|
||||||
|
else if (
|
||||||
|
allowWrappingCall &&
|
||||||
|
defaultExport &&
|
||||||
|
defaultExport.declaration.type === 'CallExpression' &&
|
||||||
|
defaultExport.declaration.arguments.length > 0 &&
|
||||||
|
defaultExport.declaration.arguments[0] &&
|
||||||
|
defaultExport.declaration.arguments[0].type === 'ObjectExpression'
|
||||||
|
) {
|
||||||
|
core.info('Found configuration object in direct default export declaration with a wrapping call')
|
||||||
|
return defaultExport.declaration.arguments[0]
|
||||||
|
}
|
||||||
|
|
||||||
// Indirect default export
|
// Indirect default export
|
||||||
else if (defaultExport && defaultExport.declaration.type === 'Identifier') {
|
else if (defaultExport && defaultExport.declaration.type === 'Identifier') {
|
||||||
const identifierName = defaultExport.declaration.name
|
const identifierName = defaultExport.declaration.name
|
||||||
const identifierDefinition = ast.body.find(
|
const identifierDeclarator = this.findTopLevelVariableDeclarator(ast, identifierName)
|
||||||
node =>
|
const identifierInitialization = identifierDeclarator && identifierDeclarator.init
|
||||||
node.type === 'VariableDeclaration' &&
|
if (identifierInitialization && identifierInitialization.type === 'ObjectExpression') {
|
||||||
node.declarations.length == 1 &&
|
|
||||||
node.declarations[0].type === 'VariableDeclarator' &&
|
|
||||||
node.declarations[0].id.type === 'Identifier' &&
|
|
||||||
node.declarations[0].id.name === identifierName &&
|
|
||||||
node.declarations[0].init.type === 'ObjectExpression'
|
|
||||||
)
|
|
||||||
if (identifierDefinition) {
|
|
||||||
core.info('Found configuration object in indirect default export declaration')
|
core.info('Found configuration object in indirect default export declaration')
|
||||||
return identifierDefinition.declarations[0].init
|
return identifierInitialization
|
||||||
|
}
|
||||||
|
// Indirect default export with a wrapping call at the definition
|
||||||
|
else if (
|
||||||
|
allowWrappingCall &&
|
||||||
|
identifierInitialization &&
|
||||||
|
identifierInitialization.type === 'CallExpression' &&
|
||||||
|
identifierInitialization.arguments.length > 0 &&
|
||||||
|
identifierInitialization.arguments[0] &&
|
||||||
|
identifierInitialization.arguments[0].type === 'ObjectExpression'
|
||||||
|
) {
|
||||||
|
core.info(
|
||||||
|
'Found configuration object in indirect default export declaration with a wrapping call at the definition'
|
||||||
|
)
|
||||||
|
return identifierInitialization.arguments[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indirect default export with a wrapping call at the export
|
||||||
|
else if (
|
||||||
|
allowWrappingCall &&
|
||||||
|
defaultExport &&
|
||||||
|
defaultExport.declaration.type === 'CallExpression' &&
|
||||||
|
defaultExport.declaration.arguments.length > 0 &&
|
||||||
|
defaultExport.declaration.arguments[0] &&
|
||||||
|
defaultExport.declaration.arguments[0].type === 'Identifier'
|
||||||
|
) {
|
||||||
|
const identifierName = defaultExport.declaration.arguments[0].name
|
||||||
|
const identifierDeclarator = this.findTopLevelVariableDeclarator(ast, identifierName)
|
||||||
|
const identifierInitialization = identifierDeclarator && identifierDeclarator.init
|
||||||
|
if (identifierInitialization && identifierInitialization.type === 'ObjectExpression') {
|
||||||
|
core.info(
|
||||||
|
'Found configuration object in indirect default export declaration with a wrapping call at the export'
|
||||||
|
)
|
||||||
|
return identifierInitialization
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15348,21 +15484,57 @@ class ConfigParser {
|
|||||||
return moduleExport.expression.right
|
return moduleExport.expression.right
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Direct default export with a wrapping call
|
||||||
|
else if (
|
||||||
|
allowWrappingCall &&
|
||||||
|
moduleExport &&
|
||||||
|
moduleExport.expression.right.type === 'CallExpression' &&
|
||||||
|
moduleExport.expression.right.arguments.length > 0 &&
|
||||||
|
moduleExport.expression.right.arguments[0] &&
|
||||||
|
moduleExport.expression.right.arguments[0].type === 'ObjectExpression'
|
||||||
|
) {
|
||||||
|
core.info('Found configuration object in direct module export with a wrapping call')
|
||||||
|
return moduleExport.expression.right.arguments[0]
|
||||||
|
}
|
||||||
|
|
||||||
// Indirect module export
|
// Indirect module export
|
||||||
else if (moduleExport && moduleExport.expression.right.type === 'Identifier') {
|
else if (moduleExport && moduleExport.expression.right.type === 'Identifier') {
|
||||||
const identifierName = moduleExport && moduleExport.expression.right.name
|
const identifierName = moduleExport && moduleExport.expression.right.name
|
||||||
const identifierDefinition = ast.body.find(
|
const identifierDeclarator = this.findTopLevelVariableDeclarator(ast, identifierName)
|
||||||
node =>
|
const identifierInitialization = identifierDeclarator && identifierDeclarator.init
|
||||||
node.type === 'VariableDeclaration' &&
|
if (identifierInitialization && identifierInitialization.type === 'ObjectExpression') {
|
||||||
node.declarations.length == 1 &&
|
|
||||||
node.declarations[0].type === 'VariableDeclarator' &&
|
|
||||||
node.declarations[0].id.type === 'Identifier' &&
|
|
||||||
node.declarations[0].id.name === identifierName &&
|
|
||||||
node.declarations[0].init.type === 'ObjectExpression'
|
|
||||||
)
|
|
||||||
if (identifierDefinition) {
|
|
||||||
core.info('Found configuration object in indirect module export')
|
core.info('Found configuration object in indirect module export')
|
||||||
return identifierDefinition.declarations[0].init
|
return identifierInitialization
|
||||||
|
}
|
||||||
|
// Indirect module export with a wrapping call at the definition
|
||||||
|
else if (
|
||||||
|
allowWrappingCall &&
|
||||||
|
identifierInitialization &&
|
||||||
|
identifierInitialization.type === 'CallExpression' &&
|
||||||
|
identifierInitialization.arguments.length > 0 &&
|
||||||
|
identifierInitialization.arguments[0] &&
|
||||||
|
identifierInitialization.arguments[0].type === 'ObjectExpression'
|
||||||
|
) {
|
||||||
|
core.info('Found configuration object in indirect module export with a wrapping call at the definition')
|
||||||
|
return identifierInitialization.arguments[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indirect module export with a wrapping call at the export
|
||||||
|
else if (
|
||||||
|
allowWrappingCall &&
|
||||||
|
moduleExport &&
|
||||||
|
moduleExport.expression.right.type === 'CallExpression' &&
|
||||||
|
moduleExport.expression.right.arguments.length > 0 &&
|
||||||
|
moduleExport.expression.right.arguments[0] &&
|
||||||
|
moduleExport.expression.right.arguments[0].type === 'Identifier'
|
||||||
|
) {
|
||||||
|
const identifierName = moduleExport.expression.right.arguments[0].name
|
||||||
|
const identifierDeclarator = this.findTopLevelVariableDeclarator(ast, identifierName)
|
||||||
|
const identifierInitialization = identifierDeclarator && identifierDeclarator.init
|
||||||
|
if (identifierInitialization && identifierInitialization.type === 'ObjectExpression') {
|
||||||
|
core.info('Found configuration object in indirect module export declaration with a wrapping call at the export')
|
||||||
|
return identifierInitialization
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15426,7 +15598,7 @@ class ConfigParser {
|
|||||||
const ast = espree.parse(this.configuration, espreeOptions)
|
const ast = espree.parse(this.configuration, espreeOptions)
|
||||||
|
|
||||||
// Find the configuration object
|
// Find the configuration object
|
||||||
var configurationObject = this.findConfigurationObject(ast)
|
var configurationObject = this.findConfigurationObject(ast, this.allowWrappingCall)
|
||||||
if (!configurationObject) {
|
if (!configurationObject) {
|
||||||
throw 'Could not find a configuration object in the configuration file'
|
throw 'Could not find a configuration object in the configuration file'
|
||||||
}
|
}
|
||||||
@@ -15600,6 +15772,8 @@ const core = __nccwpck_require__(2186)
|
|||||||
const { ConfigParser } = __nccwpck_require__(8395)
|
const { ConfigParser } = __nccwpck_require__(8395)
|
||||||
const removeTrailingSlash = __nccwpck_require__(9255)
|
const removeTrailingSlash = __nccwpck_require__(9255)
|
||||||
|
|
||||||
|
const SUPPORTED_FILE_EXTENSIONS = ['.js', '.cjs', '.mjs']
|
||||||
|
|
||||||
// Return the settings to be passed to a {ConfigParser} for a given static site generator,
|
// Return the settings to be passed to a {ConfigParser} for a given static site generator,
|
||||||
// optional configuration file path, and a Pages siteUrl value to inject
|
// optional configuration file path, and a Pages siteUrl value to inject
|
||||||
function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, siteUrl }) {
|
function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, siteUrl }) {
|
||||||
@@ -15632,7 +15806,9 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, sit
|
|||||||
|
|
||||||
// Disable server side image optimization too
|
// Disable server side image optimization too
|
||||||
// https://nextjs.org/docs/api-reference/next/image#unoptimized
|
// https://nextjs.org/docs/api-reference/next/image#unoptimized
|
||||||
'experimental.images.unoptimized': true
|
'experimental.images.unoptimized': true,
|
||||||
|
// No longer experimental as of Next.js v12.3.0
|
||||||
|
'images.unoptimized': true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'gatsby':
|
case 'gatsby':
|
||||||
@@ -15672,12 +15848,23 @@ function setPagesConfig({ staticSiteGenerator, generatorConfigFile, siteUrl }) {
|
|||||||
const settings = getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, siteUrl })
|
const settings = getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, siteUrl })
|
||||||
new ConfigParser(settings).injectAll()
|
new ConfigParser(settings).injectAll()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
const isSupportedFileExtension = SUPPORTED_FILE_EXTENSIONS.some(ext => generatorConfigFile.endsWith(ext))
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
|
if (!isSupportedFileExtension) {
|
||||||
|
core.warning(
|
||||||
|
`Unsupported configuration file extension. Currently supported extensions: ${SUPPORTED_FILE_EXTENSIONS.map(
|
||||||
|
ext => JSON.stringify(ext)
|
||||||
|
).join(', ')}`,
|
||||||
|
error
|
||||||
|
)
|
||||||
|
} else {
|
||||||
core.warning(
|
core.warning(
|
||||||
`We were unable to determine how to inject the site metadata into your config. Generated URLs may be incorrect. The base URL for this site should be ${siteUrl}. Please ensure your framework is configured to generate relative links appropriately.`,
|
`We were unable to determine how to inject the site metadata into your config. Generated URLs may be incorrect. The base URL for this site should be ${siteUrl}. Please ensure your framework is configured to generate relative links appropriately.`,
|
||||||
error
|
error
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { getConfigParserSettings, setPagesConfig }
|
module.exports = { getConfigParserSettings, setPagesConfig }
|
||||||
|
|||||||
2
dist/index.js.map
vendored
2
dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
14
package-lock.json
generated
14
package-lock.json
generated
@@ -9,7 +9,7 @@
|
|||||||
"version": "1.0.0",
|
"version": "1.0.0",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.9.1",
|
"@actions/core": "^1.10.0",
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
"espree": "^9.3.2"
|
"espree": "^9.3.2"
|
||||||
},
|
},
|
||||||
@@ -23,9 +23,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/@actions/core": {
|
"node_modules/@actions/core": {
|
||||||
"version": "1.9.1",
|
"version": "1.10.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.1.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
|
||||||
"integrity": "sha512-5ad+U2YGrmmiw6du20AQW5XuWo7UKN2052FjSV7MX+Wfjf8sCqcsZe62NfgHys4QI4/Y+vQvLKYL8jWtA1ZBTA==",
|
"integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/http-client": "^2.0.1",
|
"@actions/http-client": "^2.0.1",
|
||||||
"uuid": "^8.3.2"
|
"uuid": "^8.3.2"
|
||||||
@@ -5747,9 +5747,9 @@
|
|||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": {
|
"@actions/core": {
|
||||||
"version": "1.9.1",
|
"version": "1.10.0",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.1.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
|
||||||
"integrity": "sha512-5ad+U2YGrmmiw6du20AQW5XuWo7UKN2052FjSV7MX+Wfjf8sCqcsZe62NfgHys4QI4/Y+vQvLKYL8jWtA1ZBTA==",
|
"integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"@actions/http-client": "^2.0.1",
|
"@actions/http-client": "^2.0.1",
|
||||||
"uuid": "^8.3.2"
|
"uuid": "^8.3.2"
|
||||||
|
|||||||
@@ -24,7 +24,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/actions/configure-pages#readme",
|
"homepage": "https://github.com/actions/configure-pages#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.9.1",
|
"@actions/core": "^1.10.0",
|
||||||
"axios": "^0.27.2",
|
"axios": "^0.27.2",
|
||||||
"espree": "^9.3.2"
|
"espree": "^9.3.2"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ Pages's path based routing (and work).
|
|||||||
|
|
||||||
Supported configuration initializations:
|
Supported configuration initializations:
|
||||||
|
|
||||||
(1) Default export:
|
(1) Direct default export:
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
// configuration object here
|
// configuration object here
|
||||||
@@ -21,19 +21,69 @@ Supported configuration initializations:
|
|||||||
// configuration object here
|
// configuration object here
|
||||||
}
|
}
|
||||||
|
|
||||||
(3) Indirect module export:
|
(3) Indirect default export:
|
||||||
|
|
||||||
const config = // configuration object here
|
const config = {
|
||||||
|
// configuration object here
|
||||||
|
}
|
||||||
|
export default config
|
||||||
|
|
||||||
|
(4) Indirect module export:
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
// configuration object here
|
||||||
|
}
|
||||||
module.exports = config
|
module.exports = config
|
||||||
|
|
||||||
|
(5) Direct default export with wrapping call:
|
||||||
|
|
||||||
|
export default defineConfig({
|
||||||
|
// configuration object here
|
||||||
|
})
|
||||||
|
|
||||||
|
(6) Direct module export with wrapping call:
|
||||||
|
|
||||||
|
module.exports = defineConfig({
|
||||||
|
// configuration object here
|
||||||
|
})
|
||||||
|
|
||||||
|
(7) Indirect default export with wrapping call at the definition:
|
||||||
|
|
||||||
|
const config = defineConfig({
|
||||||
|
// configuration object here
|
||||||
|
})
|
||||||
|
export default config
|
||||||
|
|
||||||
|
(8) Indirect default export with wrapping call at the export:
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
// configuration object here
|
||||||
|
}
|
||||||
|
export default defineConfig(config)
|
||||||
|
|
||||||
|
(9) Indirect module export with wrapping call at the definition:
|
||||||
|
|
||||||
|
const config = defineConfig({
|
||||||
|
// configuration object here
|
||||||
|
})
|
||||||
|
module.exports = config
|
||||||
|
|
||||||
|
(10) Indirect module export with wrapping call at the export:
|
||||||
|
|
||||||
|
const config = {
|
||||||
|
// configuration object here
|
||||||
|
}
|
||||||
|
module.exports = defineConfig(config)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
class ConfigParser {
|
class ConfigParser {
|
||||||
// Ctor
|
// Ctor
|
||||||
// - configurationFile: path to the configuration file
|
// - configurationFile: path to the configuration file
|
||||||
// - blankConfigurationFile: a blank configuration file to use if non was previously found
|
// - blankConfigurationFile: a blank configuration file to use if non was previously found
|
||||||
constructor({ configurationFile, blankConfigurationFile, properties }) {
|
constructor({ configurationFile, blankConfigurationFile, allowWrappingCall = false, properties }) {
|
||||||
// Save field
|
// Save field
|
||||||
this.configurationFile = configurationFile
|
this.configurationFile = configurationFile
|
||||||
|
this.allowWrappingCall = allowWrappingCall === true
|
||||||
this.properties = properties
|
this.properties = properties
|
||||||
|
|
||||||
// If the configuration file does not exist, initialize it with the blank configuration file
|
// If the configuration file does not exist, initialize it with the blank configuration file
|
||||||
@@ -49,12 +99,43 @@ class ConfigParser {
|
|||||||
this.configuration = fs.readFileSync(this.configurationFile, 'utf8')
|
this.configuration = fs.readFileSync(this.configurationFile, 'utf8')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
findTopLevelVariableDeclarator(ast, identifierName) {
|
||||||
|
let targetDeclarator
|
||||||
|
ast.body.find(
|
||||||
|
node =>
|
||||||
|
node.type === 'VariableDeclaration' &&
|
||||||
|
node.declarations &&
|
||||||
|
node.declarations.length > 0 &&
|
||||||
|
node.declarations.find(declarator => {
|
||||||
|
if (
|
||||||
|
declarator.type === 'VariableDeclarator' &&
|
||||||
|
declarator.id &&
|
||||||
|
declarator.id.type === 'Identifier' &&
|
||||||
|
declarator.id.name === identifierName
|
||||||
|
) {
|
||||||
|
targetDeclarator = declarator
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
)
|
||||||
|
return targetDeclarator
|
||||||
|
}
|
||||||
|
|
||||||
// Find the configuration object in an AST.
|
// Find the configuration object in an AST.
|
||||||
// Look for a default export, a direct module export or an indirect module
|
// Look for, in order:
|
||||||
// export (in that order).
|
// - a direct default export
|
||||||
|
// - a direct default export with a wrapping call
|
||||||
|
// - an indirect default export
|
||||||
|
// - an indirect default export with a wrapping call at the definition
|
||||||
|
// - an indirect default export with a wrapping call at the export
|
||||||
|
// - a direct module export
|
||||||
|
// - a direct module export with a wrapping call
|
||||||
|
// - an indirect module export
|
||||||
|
// - an indirect module export with a wrapping call at the definition
|
||||||
|
// - an indirect module export with a wrapping call at the export
|
||||||
//
|
//
|
||||||
// Return the configuration object or null.
|
// Return the configuration object or null.
|
||||||
findConfigurationObject(ast) {
|
findConfigurationObject(ast, allowWrappingCall = false) {
|
||||||
// Try to find a default export
|
// Try to find a default export
|
||||||
var defaultExport = ast.body.find(node => node.type === 'ExportDefaultDeclaration')
|
var defaultExport = ast.body.find(node => node.type === 'ExportDefaultDeclaration')
|
||||||
|
|
||||||
@@ -64,21 +145,61 @@ class ConfigParser {
|
|||||||
return defaultExport.declaration
|
return defaultExport.declaration
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Direct default export with a wrapping call
|
||||||
|
else if (
|
||||||
|
allowWrappingCall &&
|
||||||
|
defaultExport &&
|
||||||
|
defaultExport.declaration.type === 'CallExpression' &&
|
||||||
|
defaultExport.declaration.arguments.length > 0 &&
|
||||||
|
defaultExport.declaration.arguments[0] &&
|
||||||
|
defaultExport.declaration.arguments[0].type === 'ObjectExpression'
|
||||||
|
) {
|
||||||
|
core.info('Found configuration object in direct default export declaration with a wrapping call')
|
||||||
|
return defaultExport.declaration.arguments[0]
|
||||||
|
}
|
||||||
|
|
||||||
// Indirect default export
|
// Indirect default export
|
||||||
else if (defaultExport && defaultExport.declaration.type === 'Identifier') {
|
else if (defaultExport && defaultExport.declaration.type === 'Identifier') {
|
||||||
const identifierName = defaultExport.declaration.name
|
const identifierName = defaultExport.declaration.name
|
||||||
const identifierDefinition = ast.body.find(
|
const identifierDeclarator = this.findTopLevelVariableDeclarator(ast, identifierName)
|
||||||
node =>
|
const identifierInitialization = identifierDeclarator && identifierDeclarator.init
|
||||||
node.type === 'VariableDeclaration' &&
|
if (identifierInitialization && identifierInitialization.type === 'ObjectExpression') {
|
||||||
node.declarations.length == 1 &&
|
|
||||||
node.declarations[0].type === 'VariableDeclarator' &&
|
|
||||||
node.declarations[0].id.type === 'Identifier' &&
|
|
||||||
node.declarations[0].id.name === identifierName &&
|
|
||||||
node.declarations[0].init.type === 'ObjectExpression'
|
|
||||||
)
|
|
||||||
if (identifierDefinition) {
|
|
||||||
core.info('Found configuration object in indirect default export declaration')
|
core.info('Found configuration object in indirect default export declaration')
|
||||||
return identifierDefinition.declarations[0].init
|
return identifierInitialization
|
||||||
|
}
|
||||||
|
// Indirect default export with a wrapping call at the definition
|
||||||
|
else if (
|
||||||
|
allowWrappingCall &&
|
||||||
|
identifierInitialization &&
|
||||||
|
identifierInitialization.type === 'CallExpression' &&
|
||||||
|
identifierInitialization.arguments.length > 0 &&
|
||||||
|
identifierInitialization.arguments[0] &&
|
||||||
|
identifierInitialization.arguments[0].type === 'ObjectExpression'
|
||||||
|
) {
|
||||||
|
core.info(
|
||||||
|
'Found configuration object in indirect default export declaration with a wrapping call at the definition'
|
||||||
|
)
|
||||||
|
return identifierInitialization.arguments[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indirect default export with a wrapping call at the export
|
||||||
|
else if (
|
||||||
|
allowWrappingCall &&
|
||||||
|
defaultExport &&
|
||||||
|
defaultExport.declaration.type === 'CallExpression' &&
|
||||||
|
defaultExport.declaration.arguments.length > 0 &&
|
||||||
|
defaultExport.declaration.arguments[0] &&
|
||||||
|
defaultExport.declaration.arguments[0].type === 'Identifier'
|
||||||
|
) {
|
||||||
|
const identifierName = defaultExport.declaration.arguments[0].name
|
||||||
|
const identifierDeclarator = this.findTopLevelVariableDeclarator(ast, identifierName)
|
||||||
|
const identifierInitialization = identifierDeclarator && identifierDeclarator.init
|
||||||
|
if (identifierInitialization && identifierInitialization.type === 'ObjectExpression') {
|
||||||
|
core.info(
|
||||||
|
'Found configuration object in indirect default export declaration with a wrapping call at the export'
|
||||||
|
)
|
||||||
|
return identifierInitialization
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -101,21 +222,57 @@ class ConfigParser {
|
|||||||
return moduleExport.expression.right
|
return moduleExport.expression.right
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Direct default export with a wrapping call
|
||||||
|
else if (
|
||||||
|
allowWrappingCall &&
|
||||||
|
moduleExport &&
|
||||||
|
moduleExport.expression.right.type === 'CallExpression' &&
|
||||||
|
moduleExport.expression.right.arguments.length > 0 &&
|
||||||
|
moduleExport.expression.right.arguments[0] &&
|
||||||
|
moduleExport.expression.right.arguments[0].type === 'ObjectExpression'
|
||||||
|
) {
|
||||||
|
core.info('Found configuration object in direct module export with a wrapping call')
|
||||||
|
return moduleExport.expression.right.arguments[0]
|
||||||
|
}
|
||||||
|
|
||||||
// Indirect module export
|
// Indirect module export
|
||||||
else if (moduleExport && moduleExport.expression.right.type === 'Identifier') {
|
else if (moduleExport && moduleExport.expression.right.type === 'Identifier') {
|
||||||
const identifierName = moduleExport && moduleExport.expression.right.name
|
const identifierName = moduleExport && moduleExport.expression.right.name
|
||||||
const identifierDefinition = ast.body.find(
|
const identifierDeclarator = this.findTopLevelVariableDeclarator(ast, identifierName)
|
||||||
node =>
|
const identifierInitialization = identifierDeclarator && identifierDeclarator.init
|
||||||
node.type === 'VariableDeclaration' &&
|
if (identifierInitialization && identifierInitialization.type === 'ObjectExpression') {
|
||||||
node.declarations.length == 1 &&
|
|
||||||
node.declarations[0].type === 'VariableDeclarator' &&
|
|
||||||
node.declarations[0].id.type === 'Identifier' &&
|
|
||||||
node.declarations[0].id.name === identifierName &&
|
|
||||||
node.declarations[0].init.type === 'ObjectExpression'
|
|
||||||
)
|
|
||||||
if (identifierDefinition) {
|
|
||||||
core.info('Found configuration object in indirect module export')
|
core.info('Found configuration object in indirect module export')
|
||||||
return identifierDefinition.declarations[0].init
|
return identifierInitialization
|
||||||
|
}
|
||||||
|
// Indirect module export with a wrapping call at the definition
|
||||||
|
else if (
|
||||||
|
allowWrappingCall &&
|
||||||
|
identifierInitialization &&
|
||||||
|
identifierInitialization.type === 'CallExpression' &&
|
||||||
|
identifierInitialization.arguments.length > 0 &&
|
||||||
|
identifierInitialization.arguments[0] &&
|
||||||
|
identifierInitialization.arguments[0].type === 'ObjectExpression'
|
||||||
|
) {
|
||||||
|
core.info('Found configuration object in indirect module export with a wrapping call at the definition')
|
||||||
|
return identifierInitialization.arguments[0]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Indirect module export with a wrapping call at the export
|
||||||
|
else if (
|
||||||
|
allowWrappingCall &&
|
||||||
|
moduleExport &&
|
||||||
|
moduleExport.expression.right.type === 'CallExpression' &&
|
||||||
|
moduleExport.expression.right.arguments.length > 0 &&
|
||||||
|
moduleExport.expression.right.arguments[0] &&
|
||||||
|
moduleExport.expression.right.arguments[0].type === 'Identifier'
|
||||||
|
) {
|
||||||
|
const identifierName = moduleExport.expression.right.arguments[0].name
|
||||||
|
const identifierDeclarator = this.findTopLevelVariableDeclarator(ast, identifierName)
|
||||||
|
const identifierInitialization = identifierDeclarator && identifierDeclarator.init
|
||||||
|
if (identifierInitialization && identifierInitialization.type === 'ObjectExpression') {
|
||||||
|
core.info('Found configuration object in indirect module export declaration with a wrapping call at the export')
|
||||||
|
return identifierInitialization
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -179,7 +336,7 @@ class ConfigParser {
|
|||||||
const ast = espree.parse(this.configuration, espreeOptions)
|
const ast = espree.parse(this.configuration, espreeOptions)
|
||||||
|
|
||||||
// Find the configuration object
|
// Find the configuration object
|
||||||
var configurationObject = this.findConfigurationObject(ast)
|
var configurationObject = this.findConfigurationObject(ast, this.allowWrappingCall)
|
||||||
if (!configurationObject) {
|
if (!configurationObject) {
|
||||||
throw 'Could not find a configuration object in the configuration file'
|
throw 'Could not find a configuration object in the configuration file'
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ const tempFolder = getTempFolder()
|
|||||||
// Cases to test
|
// Cases to test
|
||||||
const cases = [
|
const cases = [
|
||||||
//
|
//
|
||||||
// Default export
|
// Direct default export
|
||||||
//
|
//
|
||||||
{
|
{
|
||||||
property: 'property',
|
property: 'property',
|
||||||
@@ -97,11 +97,13 @@ const cases = [
|
|||||||
source: 'const config = {}; export default config',
|
source: 'const config = {}; export default config',
|
||||||
expected: 'const config = { property: "value"}; export default config'
|
expected: 'const config = { property: "value"}; export default config'
|
||||||
},
|
},
|
||||||
|
// with more than 1 declaration chained together
|
||||||
{
|
{
|
||||||
property: 'property',
|
property: 'property',
|
||||||
source: 'var config = {}; export default config',
|
source: 'var temp = {}, config = {}; export default config',
|
||||||
expected: 'var config = { property: "value"}; export default config'
|
expected: 'var temp = {}, config = { property: "value"}; export default config'
|
||||||
},
|
},
|
||||||
|
// deeper
|
||||||
{
|
{
|
||||||
property: 'a.b.c',
|
property: 'a.b.c',
|
||||||
source: 'var config = {}; export default config',
|
source: 'var config = {}; export default config',
|
||||||
@@ -140,11 +142,13 @@ const cases = [
|
|||||||
source: 'const config = {}; module.exports = config',
|
source: 'const config = {}; module.exports = config',
|
||||||
expected: 'const config = { property: "value"}; module.exports = config'
|
expected: 'const config = { property: "value"}; module.exports = config'
|
||||||
},
|
},
|
||||||
|
// with more than 1 declaration chained together
|
||||||
{
|
{
|
||||||
property: 'property',
|
property: 'property',
|
||||||
source: 'var config = {}; module.exports = config',
|
source: 'var temp = {}, config = {}; module.exports = config',
|
||||||
expected: 'var config = { property: "value"}; module.exports = config'
|
expected: 'var temp = {}, config = { property: "value"}; module.exports = config'
|
||||||
},
|
},
|
||||||
|
// deeper
|
||||||
{
|
{
|
||||||
property: 'a.b.c',
|
property: 'a.b.c',
|
||||||
source: 'var config = {}; module.exports = config',
|
source: 'var config = {}; module.exports = config',
|
||||||
@@ -154,6 +158,109 @@ const cases = [
|
|||||||
property: 'a.b.c',
|
property: 'a.b.c',
|
||||||
source: 'var config = { a: { b: [], c: "hello" } }; module.exports = config',
|
source: 'var config = { a: { b: [], c: "hello" } }; module.exports = config',
|
||||||
expected: 'var config = { a: { b: { c: "value"}, c: "hello" } }; module.exports = config'
|
expected: 'var config = { a: { b: { c: "value"}, c: "hello" } }; module.exports = config'
|
||||||
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
// Direct default export with wrapping call
|
||||||
|
//
|
||||||
|
{
|
||||||
|
property: 'property',
|
||||||
|
source: 'import { defineConfig } from "astro/config"; export default defineConfig({ p1: 0 })',
|
||||||
|
expected: 'import { defineConfig } from "astro/config"; export default defineConfig({ property: "value", p1: 0 })',
|
||||||
|
allowWrappingCall: true
|
||||||
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
// Direct module exports with wrapping call
|
||||||
|
//
|
||||||
|
{
|
||||||
|
property: 'property',
|
||||||
|
source: 'const { defineConfig } = require("astro/config"); module.exports = defineConfig({ p1: 0 })',
|
||||||
|
expected:
|
||||||
|
'const { defineConfig } = require("astro/config"); module.exports = defineConfig({ property: "value", p1: 0 })',
|
||||||
|
allowWrappingCall: true
|
||||||
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
// Indirect default export with wrapping call at the definition
|
||||||
|
//
|
||||||
|
{
|
||||||
|
property: 'property',
|
||||||
|
source: 'import { defineConfig } from "astro/config"; const config = defineConfig({}); export default config',
|
||||||
|
expected:
|
||||||
|
'import { defineConfig } from "astro/config"; const config = defineConfig({ property: "value" }); export default config',
|
||||||
|
allowWrappingCall: true
|
||||||
|
},
|
||||||
|
// with more than 1 declaration chained together
|
||||||
|
{
|
||||||
|
property: 'property',
|
||||||
|
source:
|
||||||
|
'import { defineConfig } from "astro/config"; const temp = {}, config = defineConfig({}); export default config',
|
||||||
|
expected:
|
||||||
|
'import { defineConfig } from "astro/config"; const temp = {}, config = defineConfig({ property: "value" }); export default config',
|
||||||
|
allowWrappingCall: true
|
||||||
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
// Indirect default export with wrapping call at the export
|
||||||
|
//
|
||||||
|
{
|
||||||
|
property: 'property',
|
||||||
|
source: 'import { defineConfig } from "astro/config"; const config = {}; export default defineConfig(config)',
|
||||||
|
expected:
|
||||||
|
'import { defineConfig } from "astro/config"; const config = { property: "value" }; export default defineConfig(config)',
|
||||||
|
allowWrappingCall: true
|
||||||
|
},
|
||||||
|
// with more than 1 declaration chained together
|
||||||
|
{
|
||||||
|
property: 'property',
|
||||||
|
source:
|
||||||
|
'import { defineConfig } from "astro/config"; const temp = {}, config = {}; export default defineConfig(config)',
|
||||||
|
expected:
|
||||||
|
'import { defineConfig } from "astro/config"; const temp = {}, config = { property: "value" }; export default defineConfig(config)',
|
||||||
|
allowWrappingCall: true
|
||||||
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
// Indirect module exports with wrapping call at the definition
|
||||||
|
//
|
||||||
|
{
|
||||||
|
property: 'property',
|
||||||
|
source:
|
||||||
|
'const { defineConfig } = require("astro/config"); const config = defineConfig({}); module.exports = config',
|
||||||
|
expected:
|
||||||
|
'const { defineConfig } = require("astro/config"); const config = defineConfig({ property: "value"}); module.exports = config',
|
||||||
|
allowWrappingCall: true
|
||||||
|
},
|
||||||
|
// with more than 1 declaration chained together
|
||||||
|
{
|
||||||
|
property: 'property',
|
||||||
|
source:
|
||||||
|
'const { defineConfig } = require("astro/config"); const temp = {}, config = defineConfig({}); module.exports = config',
|
||||||
|
expected:
|
||||||
|
'const { defineConfig } = require("astro/config"); const temp = {}, config = defineConfig({ property: "value"}); module.exports = config',
|
||||||
|
allowWrappingCall: true
|
||||||
|
},
|
||||||
|
|
||||||
|
//
|
||||||
|
// Indirect module exports with wrapping call at the export
|
||||||
|
//
|
||||||
|
{
|
||||||
|
property: 'property',
|
||||||
|
source:
|
||||||
|
'const { defineConfig } = require("astro/config"); const config = {}; module.exports = defineConfig(config)',
|
||||||
|
expected:
|
||||||
|
'const { defineConfig } = require("astro/config"); const config = { property: "value"}; module.exports = defineConfig(config)',
|
||||||
|
allowWrappingCall: true
|
||||||
|
},
|
||||||
|
// with more than 1 declaration chained together
|
||||||
|
{
|
||||||
|
property: 'property',
|
||||||
|
source:
|
||||||
|
'const { defineConfig } = require("astro/config"); const temp = {}, config = {}; module.exports = defineConfig(config)',
|
||||||
|
expected:
|
||||||
|
'const { defineConfig } = require("astro/config"); const temp = {}, config = { property: "value"}; module.exports = defineConfig(config)',
|
||||||
|
allowWrappingCall: true
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -168,7 +275,7 @@ describe('config-parser', () => {
|
|||||||
jest.spyOn(core, 'debug').mockImplementation(jest.fn())
|
jest.spyOn(core, 'debug').mockImplementation(jest.fn())
|
||||||
})
|
})
|
||||||
|
|
||||||
cases.forEach(({ property, source, expected }, index) => {
|
cases.forEach(({ property, source, expected, allowWrappingCall = false }, index) => {
|
||||||
it(`injects path properly for case #${index}`, () => {
|
it(`injects path properly for case #${index}`, () => {
|
||||||
// Write the source file
|
// Write the source file
|
||||||
const sourceFile = `${tempFolder}/source.js`
|
const sourceFile = `${tempFolder}/source.js`
|
||||||
@@ -180,7 +287,8 @@ describe('config-parser', () => {
|
|||||||
|
|
||||||
// Update the settings and do the injection
|
// Update the settings and do the injection
|
||||||
new ConfigParser({
|
new ConfigParser({
|
||||||
configurationFile: sourceFile
|
configurationFile: sourceFile,
|
||||||
|
allowWrappingCall
|
||||||
}).inject(property, 'value')
|
}).inject(property, 'value')
|
||||||
|
|
||||||
// Compare the files
|
// Compare the files
|
||||||
|
|||||||
@@ -1,3 +1,3 @@
|
|||||||
// Default Pages configuration for Next
|
// Default Pages configuration for Next
|
||||||
const nextConfig = { experimental: { images: { unoptimized: true } }, basePath: '/docs' }
|
const nextConfig = { images: { unoptimized: true }, experimental: { images: { unoptimized: true } }, basePath: '/docs' }
|
||||||
module.exports = nextConfig
|
module.exports = nextConfig
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
|
images: { unoptimized: true },
|
||||||
experimental: { images: { unoptimized: true } },
|
experimental: { images: { unoptimized: true } },
|
||||||
basePath: '/docs',
|
basePath: '/docs',
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
|
images: { unoptimized: true },
|
||||||
experimental: { images: { unoptimized: true } },
|
experimental: { images: { unoptimized: true } },
|
||||||
basePath: '/docs',
|
basePath: '/docs',
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
/** @type {import('next').NextConfig} */
|
/** @type {import('next').NextConfig} */
|
||||||
const nextConfig = {
|
const nextConfig = {
|
||||||
|
images: { unoptimized: true },
|
||||||
experimental: { images: { unoptimized: true } },
|
experimental: { images: { unoptimized: true } },
|
||||||
basePath: '/docs',
|
basePath: '/docs',
|
||||||
reactStrictMode: true,
|
reactStrictMode: true,
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ const core = require('@actions/core')
|
|||||||
const { ConfigParser } = require('./config-parser')
|
const { ConfigParser } = require('./config-parser')
|
||||||
const removeTrailingSlash = require('./remove-trailing-slash')
|
const removeTrailingSlash = require('./remove-trailing-slash')
|
||||||
|
|
||||||
|
const SUPPORTED_FILE_EXTENSIONS = ['.js', '.cjs', '.mjs']
|
||||||
|
|
||||||
// Return the settings to be passed to a {ConfigParser} for a given static site generator,
|
// Return the settings to be passed to a {ConfigParser} for a given static site generator,
|
||||||
// optional configuration file path, and a Pages siteUrl value to inject
|
// optional configuration file path, and a Pages siteUrl value to inject
|
||||||
function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, siteUrl }) {
|
function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, siteUrl }) {
|
||||||
@@ -34,7 +36,9 @@ function getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, sit
|
|||||||
|
|
||||||
// Disable server side image optimization too
|
// Disable server side image optimization too
|
||||||
// https://nextjs.org/docs/api-reference/next/image#unoptimized
|
// https://nextjs.org/docs/api-reference/next/image#unoptimized
|
||||||
'experimental.images.unoptimized': true
|
'experimental.images.unoptimized': true,
|
||||||
|
// No longer experimental as of Next.js v12.3.0
|
||||||
|
'images.unoptimized': true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case 'gatsby':
|
case 'gatsby':
|
||||||
@@ -74,12 +78,23 @@ function setPagesConfig({ staticSiteGenerator, generatorConfigFile, siteUrl }) {
|
|||||||
const settings = getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, siteUrl })
|
const settings = getConfigParserSettings({ staticSiteGenerator, generatorConfigFile, siteUrl })
|
||||||
new ConfigParser(settings).injectAll()
|
new ConfigParser(settings).injectAll()
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
const isSupportedFileExtension = SUPPORTED_FILE_EXTENSIONS.some(ext => generatorConfigFile.endsWith(ext))
|
||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
|
if (!isSupportedFileExtension) {
|
||||||
|
core.warning(
|
||||||
|
`Unsupported configuration file extension. Currently supported extensions: ${SUPPORTED_FILE_EXTENSIONS.map(
|
||||||
|
ext => JSON.stringify(ext)
|
||||||
|
).join(', ')}`,
|
||||||
|
error
|
||||||
|
)
|
||||||
|
} else {
|
||||||
core.warning(
|
core.warning(
|
||||||
`We were unable to determine how to inject the site metadata into your config. Generated URLs may be incorrect. The base URL for this site should be ${siteUrl}. Please ensure your framework is configured to generate relative links appropriately.`,
|
`We were unable to determine how to inject the site metadata into your config. Generated URLs may be incorrect. The base URL for this site should be ${siteUrl}. Please ensure your framework is configured to generate relative links appropriately.`,
|
||||||
error
|
error
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = { getConfigParserSettings, setPagesConfig }
|
module.exports = { getConfigParserSettings, setPagesConfig }
|
||||||
|
|||||||
@@ -11,6 +11,13 @@ const tempFolder = getTempFolder()
|
|||||||
|
|
||||||
const SUPPORTED_GENERATORS = ['next', 'nuxt', 'gatsby', 'sveltekit']
|
const SUPPORTED_GENERATORS = ['next', 'nuxt', 'gatsby', 'sveltekit']
|
||||||
const SUPPORTED_FILE_EXTENSIONS = ['.js', '.cjs', '.mjs']
|
const SUPPORTED_FILE_EXTENSIONS = ['.js', '.cjs', '.mjs']
|
||||||
|
const IS_BLANK_CONFIG_FILE_REGEX = new RegExp(
|
||||||
|
'^blank\\.(' + SUPPORTED_FILE_EXTENSIONS.map(ext => ext.slice(1)).join('|') + ')$'
|
||||||
|
)
|
||||||
|
|
||||||
|
function isBlankConfigFileName(fileName) {
|
||||||
|
return IS_BLANK_CONFIG_FILE_REGEX.test(fileName)
|
||||||
|
}
|
||||||
|
|
||||||
// Test suite
|
// Test suite
|
||||||
describe('configParser', () => {
|
describe('configParser', () => {
|
||||||
@@ -44,7 +51,7 @@ describe('configParser', () => {
|
|||||||
// Copy the source fixture to a temp file
|
// Copy the source fixture to a temp file
|
||||||
const fixtureSourceFile = `${fixtureFolder}/${configurationFile}`
|
const fixtureSourceFile = `${fixtureFolder}/${configurationFile}`
|
||||||
const fixtureTargetFile = `${tempFolder}/${configurationFile}`
|
const fixtureTargetFile = `${tempFolder}/${configurationFile}`
|
||||||
if (configurationFile !== 'blank.js') {
|
if (!isBlankConfigFileName(configurationFile)) {
|
||||||
fs.copyFileSync(fixtureSourceFile, fixtureTargetFile)
|
fs.copyFileSync(fixtureSourceFile, fixtureTargetFile)
|
||||||
} else if (fs.existsSync(fixtureTargetFile)) {
|
} else if (fs.existsSync(fixtureTargetFile)) {
|
||||||
fs.rmSync(fixtureTargetFile)
|
fs.rmSync(fixtureTargetFile)
|
||||||
@@ -77,7 +84,7 @@ describe('configParser', () => {
|
|||||||
// Copy the source fixture to a temp file
|
// Copy the source fixture to a temp file
|
||||||
const fixtureSourceFile = `${fixtureFolder}/${configurationFile}`
|
const fixtureSourceFile = `${fixtureFolder}/${configurationFile}`
|
||||||
const fixtureTargetFile = `${tempFolder}/${configurationFile}`
|
const fixtureTargetFile = `${tempFolder}/${configurationFile}`
|
||||||
if (configurationFile !== 'blank.js') {
|
if (!isBlankConfigFileName(configurationFile)) {
|
||||||
fs.copyFileSync(fixtureSourceFile, fixtureTargetFile)
|
fs.copyFileSync(fixtureSourceFile, fixtureTargetFile)
|
||||||
} else if (fs.existsSync(fixtureTargetFile)) {
|
} else if (fs.existsSync(fixtureTargetFile)) {
|
||||||
fs.rmSync(fixtureTargetFile)
|
fs.rmSync(fixtureTargetFile)
|
||||||
|
|||||||
Reference in New Issue
Block a user