Update dist for testing

This commit is contained in:
James M. Greene
2022-07-19 12:59:37 -05:00
parent f830cbcb66
commit 2d3e762f19
3 changed files with 297 additions and 325 deletions

586
dist/index.js vendored
View File

@@ -14000,107 +14000,6 @@ function plural(ms, msAbs, n, name) {
} }
/***/ }),
/***/ 3259:
/***/ (function(module) {
void function(global) {
'use strict';
// ValueError :: String -> Error
function ValueError(message) {
var err = new Error(message);
err.name = 'ValueError';
return err;
}
// defaultTo :: a,a? -> a
function defaultTo(x, y) {
return y == null ? x : y;
}
// create :: Object -> String,*... -> String
function create(transformers) {
return function(template) {
var args = Array.prototype.slice.call(arguments, 1);
var idx = 0;
var state = 'UNDEFINED';
return template.replace(
/([{}])\1|[{](.*?)(?:!(.+?))?[}]/g,
function(match, literal, _key, xf) {
if (literal != null) {
return literal;
}
var key = _key;
if (key.length > 0) {
if (state === 'IMPLICIT') {
throw ValueError('cannot switch from ' +
'implicit to explicit numbering');
}
state = 'EXPLICIT';
} else {
if (state === 'EXPLICIT') {
throw ValueError('cannot switch from ' +
'explicit to implicit numbering');
}
state = 'IMPLICIT';
key = String(idx);
idx += 1;
}
var value = defaultTo('', lookup(args, key.split('.')));
if (xf == null) {
return value;
} else if (Object.prototype.hasOwnProperty.call(transformers, xf)) {
return transformers[xf](value);
} else {
throw ValueError('no transformer named "' + xf + '"');
}
}
);
};
}
function lookup(_obj, _path) {
var obj = _obj;
var path = _path;
if (!/^\d+$/.test(path[0])) {
path = ['0'].concat(path);
}
for (var idx = 0; idx < path.length; idx += 1) {
var key = path[idx];
obj = typeof obj[key] === 'function' ? obj[key]() : obj[key];
}
return obj;
}
// format :: String,*... -> String
var format = create({});
// format.create :: Object -> String,*... -> String
format.create = create;
// format.extend :: Object,Object -> ()
format.extend = function(prototype, transformers) {
var $format = create(transformers);
prototype.format = function() {
var args = Array.prototype.slice.call(arguments);
args.unshift(this);
return $format.apply(global, args);
};
};
/* istanbul ignore else */
if (true) {
module.exports = format;
} else {}
}.call(this, this);
/***/ }), /***/ }),
/***/ 9318: /***/ 9318:
@@ -14531,206 +14430,282 @@ exports.debug = debug; // for test
const fs = __nccwpck_require__(7147) const fs = __nccwpck_require__(7147)
const espree = __nccwpck_require__(6910) const espree = __nccwpck_require__(6910)
const format = __nccwpck_require__(3259) const prettier = __nccwpck_require__(9729)
const core = __nccwpck_require__(2186) const core = __nccwpck_require__(2186)
// Parse the AST /*
const espreeOptions = { Parse a JavaScript based configuration file and initialize or update a given property.
ecmaVersion: 6, This is used to make sure most static site generators can automatically handle
sourceType: 'module', Pages's path based routing.
range: true
} Supported configuration initializations:
(1) Default export:
export default {
// configuration object here
}
(2) Direct module export:
module.exports = {
// configuration object here
}
(3) Indirect module export:
const config = // configuration object here
module.exports = config
*/
class ConfigParser { class ConfigParser {
constructor(staticSiteConfig) { // Ctor
this.pathPropertyNuxt = `router: {\n base: '{0}'\n }` // - configurationFile: path to the configuration file
this.pathPropertyNext = `basePath: '{0}'` // - propertyName: name of the property to update (or set)
this.pathPropertyGatsby = `pathPrefix: '{0}'` // - propertyValue: value of the property to update (or set)
this.configskeleton = `export default {\n {0}\n}` // - blankConfigurationFile: a blank configuration file to use if non was previously found
this.staticSiteConfig = staticSiteConfig constructor({
this.config = fs.existsSync(this.staticSiteConfig.filePath) configurationFile,
? fs.readFileSync(this.staticSiteConfig.filePath, 'utf8') propertyName,
: null propertyValue,
this.validate() blankConfigurationFile
}) {
// Save fields
this.configurationFile = configurationFile
this.propertyName = propertyName
this.propertyValue = propertyValue
// If the configuration file does not exist, initialize it with the blank configuration file
if (!fs.existsSync(this.configurationFile)) {
core.info('Use default blank configuration')
const blankConfiguration = fs.readFileSync(blankConfigurationFile, 'utf8')
fs.writeFileSync(this.configurationFile, blankConfiguration, {
encoding: 'utf8'
})
} }
validate() { // Read the configuration file
if (!this.config) { core.info('Read existing configuration')
core.info(`original raw configuration was empty:\n${this.config}`) this.configuration = fs.readFileSync(this.configurationFile, 'utf8')
core.info('Generating a default configuration to start from...')
// Update the `config` property with a default configuration file
this.config = this.generateConfigFile()
}
} }
generateConfigFile() { // Find the configuration object in an AST.
switch (this.staticSiteConfig.type) { // Look for a default export, a direct module export or an indirect module
case 'nuxt': // export (in that order).
return format( //
this.configskeleton, // Return the configuration object or null.
format(this.pathPropertyNuxt, this.staticSiteConfig.newPath) findConfigurationObject(ast) {
// Try to find a default export
var defaultExport = ast.body.find(
node =>
node.type === 'ExportDefaultDeclaration' &&
node.declaration.type === 'ObjectExpression'
) )
break if (defaultExport) {
case 'next': core.info('Found configuration object in default export declaration')
return format( return defaultExport.declaration
this.configskeleton, }
format(this.pathPropertyNext, this.staticSiteConfig.newPath)
// Try to find a module export
var moduleExport = ast.body.find(
node =>
node.type === 'ExpressionStatement' &&
node.expression.type === 'AssignmentExpression' &&
node.expression.operator === '=' &&
node.expression.left.type === 'MemberExpression' &&
node.expression.left.object.type === 'Identifier' &&
node.expression.left.object.name === 'module' &&
node.expression.left.property.type === 'Identifier' &&
node.expression.left.property.name === 'exports'
) )
break
case 'gatsby': // Direct module export
return format( if (
this.configskeleton, moduleExport &&
format(this.pathPropertyGatsby, this.staticSiteConfig.newPath) moduleExport.expression.right.type === 'ObjectExpression'
) {
core.info('Found configuration object in direct module export')
return moduleExport.expression.right
}
// Indirect module export
else if (
moduleExport &&
moduleExport.expression.right.type === 'Identifier'
) {
const identifierName = moduleExport && moduleExport.expression.right.name
const identifierDefinition = ast.body.find(
node =>
node.type === 'VariableDeclaration' &&
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'
) )
break if (identifierDefinition) {
default: core.info('Found configuration object in indirect module export')
throw 'Unknown config type' return identifierDefinition.declarations[0].init
} }
} }
generateConfigProperty() { // No configuration object found
switch (this.staticSiteConfig.type) { return null
case 'nuxt': }
return format(this.pathPropertyNuxt, this.staticSiteConfig.newPath)
break // Find a property with a given name on a given object.
case 'next': //
return format(this.pathPropertyNext, this.staticSiteConfig.newPath) // Return the matching property or null.
break findProperty(object, name) {
case 'gatsby': // Try to find a property matching a given name
return format(this.pathPropertyGatsby, this.staticSiteConfig.newPath) const property =
break object.type === 'ObjectExpression' &&
default: object.properties.find(
throw 'Unknown config type' node => node.key.type === 'Identifier' && node.key.name === name
)
// Return the property's value (if found) or null
if (property) {
return property.value
}
return null
}
// Generate a (nested) property declaration.
// - properties: list of properties to generate
// - startIndex: the index at which to start in the declaration
//
// Return a nested property declaration as a string.
getPropertyDeclaration(properties, startIndex) {
if (startIndex === properties.length - 1) {
return `${properties[startIndex]}: "${this.propertyValue}"`
} else {
return (
`${properties[startIndex]}: {` +
this.getPropertyDeclaration(properties, startIndex + 1) +
'}'
)
} }
} }
parse() { parse() {
core.info(`original configuration:\n${this.config}`) // Logging
const ast = espree.parse(this.config, espreeOptions) core.info(`Parsing configuration:\n${this.configuration}`)
// Find the default export declaration node // Parse the AST out of the configuration file
var exportNode = ast.body.find(node => node.type === 'ExpressionStatement') const espreeOptions = {
if (exportNode) { ecmaVersion: 6,
var property = this.getPropertyModuleExport(exportNode) sourceType: 'module',
} else { range: true
exportNode = ast.body.find( }
node => node.type === 'ExportDefaultDeclaration' const ast = espree.parse(this.configuration, espreeOptions)
)
if (!exportNode) throw 'Unable to find default export' // Find the configuration object
var property = this.getPropertyExportDefault(exportNode) var configurationObject = this.findConfigurationObject(ast)
if (!configurationObject) {
throw 'Could not find a configuration object in the configuration file'
} }
if (property) { // A property may be nested in the configuration file. Split the property name with `.`
switch (this.staticSiteConfig.type) { // then walk the configuration object one property at a time.
case 'nuxt': var depth = 0
this.parseNuxt(property) const properties = this.propertyName.split('.')
var lastNode = configurationObject
while (1) {
// Find the node for the current property
var propertyNode = this.findProperty(lastNode, properties[depth])
// Update last node
if (propertyNode != null) {
lastNode = propertyNode
depth++
}
// Exit when exiting the current configuration object
if (propertyNode == null || depth >= properties.length) {
break break
case 'next':
case 'gatsby':
this.parseNextGatsby(property)
break
default:
throw 'Unknown config type'
}
}
core.info(`parsed configuration:\n${this.config}`)
fs.writeFileSync(this.staticSiteConfig.filePath, this.config)
return this.config
}
getPropertyModuleExport(exportNode) {
var propertyNode = exportNode.expression.right.properties.find(
node =>
node.key.type === 'Identifier' &&
node.key.name === this.staticSiteConfig.pathName
)
if (!propertyNode) {
core.info(
'Unable to find property, insert it : ' +
this.staticSiteConfig.pathName
)
if (exportNode.expression.right.properties.length > 0) {
this.config =
this.config.slice(
0,
exportNode.expression.right.properties[0].range[0]
) +
this.generateConfigProperty() +
',\n' +
this.config.slice(exportNode.expression.right.properties[0].range[0])
core.info('new config = \n' + this.config)
} else {
this.config =
this.config.slice(0, exportNode.expression.right.range[0] + 1) +
'\n ' +
this.generateConfigProperty() +
'\n' +
this.config.slice(exportNode.expression.right.range[1] - 1)
core.info('new config = \n' + this.config)
}
}
return propertyNode
}
getPropertyExportDefault(exportNode) {
var propertyNode = exportNode.declaration.properties.find(
node =>
node.key.type === 'Identifier' &&
node.key.name === this.staticSiteConfig.pathName
)
if (!propertyNode) {
core.info(
'Unable to find property, insert it ' + this.staticSiteConfig.pathName
)
if (exportNode.declaration.properties.length > 0) {
this.config =
this.config.slice(0, exportNode.declaration.properties[0].range[0]) +
this.generateConfigProperty() +
',\n' +
this.config.slice(exportNode.declaration.properties[0].range[0])
core.info('new config = \n' + this.config)
} else {
this.config =
this.config.slice(0, exportNode.declaration.range[0] + 1) +
'\n ' +
this.generateConfigProperty() +
'\n' +
this.config.slice(exportNode.declaration.range[1] - 1)
core.info('new config = \n' + this.config)
} }
} }
return propertyNode // If the configuration file is defining the property we are after, update it.
if (depth == properties.length) {
// The last node identified is an object expression, so do the assignment
if (lastNode.type === 'ObjectExpression') {
this.configuration =
this.configuration.slice(0, lastNode.value.range[0]) +
`"${this.propertyValue}"` +
this.configuration.slice(lastNode.value.range[1])
} }
parseNuxt(propertyNode) { // A misc object was found in the configuration file (e.g. an array, a string, a boolean,
// Find the base node // a number, etc.), just replace the whole range by our declaration
if (propertyNode && propertyNode.value.type === 'ObjectExpression') { else {
var baseNode = propertyNode.value.properties.find( this.configuration =
node => this.configuration.slice(0, lastNode.range[0]) +
node.key.type === 'Identifier' && `"${this.propertyValue}"` +
node.key.name === this.staticSiteConfig.subPathName this.configuration.slice(lastNode.range[1])
) //'base')
if (baseNode) {
// Swap the base value by a hardcoded string and print it
this.config =
this.config.slice(0, baseNode.value.range[0]) +
`'${this.staticSiteConfig.newPath}'` +
this.config.slice(baseNode.value.range[1])
}
} }
} }
parseNextGatsby(pathNode) { // Create nested properties in the configuration file
if (pathNode) { else {
this.config = // Build the declaration to inject
this.config.slice(0, pathNode.value.range[0]) + const declaration = this.getPropertyDeclaration(properties, depth)
`'${this.staticSiteConfig.newPath}'` +
this.config.slice(pathNode.value.range[1]) // The last node identified is an object expression, so do the assignment
if (lastNode.type === 'ObjectExpression') {
// The object is blank (no properties) so replace the whole range by a new object containing the declaration
if (lastNode.properties.length === 0) {
this.configuration =
this.configuration.slice(0, lastNode.range[0]) +
'{' +
declaration +
'}' +
this.configuration.slice(lastNode.range[1])
} }
// The object contains other properties, prepend our new one at the beginning
else {
this.configuration =
this.configuration.slice(0, lastNode.properties[0].range[0]) +
declaration +
',' +
this.configuration.slice(lastNode.properties[0].range[0])
}
}
// A misc object was found in the configuration file (e.g. an array, a string, a boolean,
// a number, etc.), just replace the whole range by our declaration
else {
this.configuration =
this.configuration.slice(0, lastNode.range[0]) +
declaration +
this.configuration.slice(lastNode.range[1])
}
}
// Format the updated configuration with prettier's default settings
this.configuration = prettier.format(this.configuration, {
parser: 'espree',
// Matching this repo's prettier configuration
printWidth: 80,
tabWidth: 2,
useTabs: false,
semi: false,
singleQuote: true,
trailingComma: 'none',
bracketSpacing: false,
arrowParens: 'avoid'
})
// Logging
core.info(`Parsing configuration:\n${this.configuration}`)
// Finally write the new configuration in the file
fs.writeFileSync(this.configurationFile, this.configuration, {
encoding: 'utf8'
})
} }
} }
@@ -14854,43 +14829,40 @@ module.exports = getPagesBaseUrl
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => { /***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
const core = __nccwpck_require__(2186) const core = __nccwpck_require__(2186)
const axios = __nccwpck_require__(6545)
const {ConfigParser} = __nccwpck_require__(8395) const {ConfigParser} = __nccwpck_require__(8395)
function getParserConfiguration(staticSiteGenerator, path) {
switch (staticSiteGenerator) {
case 'nuxt':
return {
configurationFile: './nuxt.config.js',
propertyName: 'router.base',
propertyValue: path,
blankConfigurationFile: `${process.cwd()}/blank-configurations/nuxt.js`
}
case 'next':
return {
configurationFile: './next.config.js',
propertyName: 'basePath',
propertyValue: path,
blankConfigurationFile: `${process.cwd()}/blank-configurations/next.js`
}
case 'gatsby':
return {
configurationFile: './gatsby-config.js',
propertyName: 'pathPrefix',
propertyValue: path,
blankConfigurationFile: `${process.cwd()}/blank-configurations/gatsby.js`
}
default:
throw `Unsupported static site generator: ${staticSiteGenerator}`
}
}
async function setPagesPath({staticSiteGenerator, path}) { async function setPagesPath({staticSiteGenerator, path}) {
try { try {
switch (staticSiteGenerator) { // Parse/mutate the configuration file
case 'nuxt': new ConfigParser(getParserConfiguration(staticSiteGenerator, path)).parse()
var ssConfig = {
filePath: './nuxt.config.js',
type: 'nuxt',
pathName: 'router',
subPathName: 'base',
newPath: path
}
break
case 'next':
var ssConfig = {
filePath: './next.config.js',
type: 'next',
pathName: 'basePath',
newPath: path
}
break
case 'gatsby':
var ssConfig = {
filePath: './gatsby-config.js',
type: 'gatsby',
pathName: 'pathPrefix',
newPath: path
}
break
default:
throw 'Unknown config type'
}
let configParser = new ConfigParser(ssConfig)
configParser.parse()
} catch (error) { } catch (error) {
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 ${path}. 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 ${path}. Please ensure your framework is configured to generate relative links appropriately.`,
@@ -14902,6 +14874,14 @@ async function setPagesPath({staticSiteGenerator, path}) {
module.exports = setPagesPath module.exports = setPagesPath
/***/ }),
/***/ 9729:
/***/ ((module) => {
module.exports = eval("require")("prettier");
/***/ }), /***/ }),
/***/ 9491: /***/ 9491:

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

28
dist/licenses.txt vendored
View File

@@ -35,6 +35,16 @@ WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@vercel/ncc
MIT
Copyright 2018 ZEIT, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
acorn acorn
MIT MIT
MIT License MIT License
@@ -572,24 +582,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
string-format
(WTFPL OR MIT)
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (c) 2018 David Chambers <dc@davidchambers.me>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
supports-color supports-color
MIT MIT
MIT License MIT License