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

590
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:
@@ -14531,206 +14430,282 @@ exports.debug = debug; // for test
const fs = __nccwpck_require__(7147)
const espree = __nccwpck_require__(6910)
const format = __nccwpck_require__(3259)
const prettier = __nccwpck_require__(9729)
const core = __nccwpck_require__(2186)
// Parse the AST
/*
Parse a JavaScript based configuration file and initialize or update a given property.
This is used to make sure most static site generators can automatically handle
Pages's path based routing.
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 {
// Ctor
// - configurationFile: path to the configuration file
// - propertyName: name of the property to update (or set)
// - propertyValue: value of the property to update (or set)
// - blankConfigurationFile: a blank configuration file to use if non was previously found
constructor({
configurationFile,
propertyName,
propertyValue,
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'
})
}
// Read the configuration file
core.info('Read existing configuration')
this.configuration = fs.readFileSync(this.configurationFile, 'utf8')
}
// Find the configuration object in an AST.
// Look for a default export, a direct module export or an indirect module
// export (in that order).
//
// Return the configuration object or null.
findConfigurationObject(ast) {
// Try to find a default export
var defaultExport = ast.body.find(
node =>
node.type === 'ExportDefaultDeclaration' &&
node.declaration.type === 'ObjectExpression'
)
if (defaultExport) {
core.info('Found configuration object in default export declaration')
return defaultExport.declaration
}
// 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'
)
// Direct module export
if (
moduleExport &&
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'
)
if (identifierDefinition) {
core.info('Found configuration object in indirect module export')
return identifierDefinition.declarations[0].init
}
}
// No configuration object found
return null
}
// Find a property with a given name on a given object.
//
// Return the matching property or null.
findProperty(object, name) {
// Try to find a property matching a given name
const property =
object.type === 'ObjectExpression' &&
object.properties.find(
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() {
// Logging
core.info(`Parsing configuration:\n${this.configuration}`)
// Parse the AST out of the configuration file
const espreeOptions = {
ecmaVersion: 6,
sourceType: 'module',
range: true
}
const ast = espree.parse(this.configuration, espreeOptions)
class ConfigParser {
constructor(staticSiteConfig) {
this.pathPropertyNuxt = `router: {\n base: '{0}'\n }`
this.pathPropertyNext = `basePath: '{0}'`
this.pathPropertyGatsby = `pathPrefix: '{0}'`
this.configskeleton = `export default {\n {0}\n}`
this.staticSiteConfig = staticSiteConfig
this.config = fs.existsSync(this.staticSiteConfig.filePath)
? fs.readFileSync(this.staticSiteConfig.filePath, 'utf8')
: null
this.validate()
// Find the configuration object
var configurationObject = this.findConfigurationObject(ast)
if (!configurationObject) {
throw 'Could not find a configuration object in the configuration file'
}
validate() {
if (!this.config) {
core.info(`original raw configuration was empty:\n${this.config}`)
core.info('Generating a default configuration to start from...')
// A property may be nested in the configuration file. Split the property name with `.`
// then walk the configuration object one property at a time.
var depth = 0
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 the `config` property with a default configuration file
this.config = this.generateConfigFile()
}
// Update last node
if (propertyNode != null) {
lastNode = propertyNode
depth++
}
generateConfigFile() {
switch (this.staticSiteConfig.type) {
case 'nuxt':
return format(
this.configskeleton,
format(this.pathPropertyNuxt, this.staticSiteConfig.newPath)
)
// Exit when exiting the current configuration object
if (propertyNode == null || depth >= properties.length) {
break
case 'next':
return format(
this.configskeleton,
format(this.pathPropertyNext, this.staticSiteConfig.newPath)
)
break
case 'gatsby':
return format(
this.configskeleton,
format(this.pathPropertyGatsby, this.staticSiteConfig.newPath)
)
break
default:
throw 'Unknown config type'
}
}
generateConfigProperty() {
switch (this.staticSiteConfig.type) {
case 'nuxt':
return format(this.pathPropertyNuxt, this.staticSiteConfig.newPath)
break
case 'next':
return format(this.pathPropertyNext, this.staticSiteConfig.newPath)
break
case 'gatsby':
return format(this.pathPropertyGatsby, this.staticSiteConfig.newPath)
break
default:
throw 'Unknown config type'
// 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])
}
// 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]) +
`"${this.propertyValue}"` +
this.configuration.slice(lastNode.range[1])
}
}
parse() {
core.info(`original configuration:\n${this.config}`)
const ast = espree.parse(this.config, espreeOptions)
// Create nested properties in the configuration file
else {
// Build the declaration to inject
const declaration = this.getPropertyDeclaration(properties, depth)
// Find the default export declaration node
var exportNode = ast.body.find(node => node.type === 'ExpressionStatement')
if (exportNode) {
var property = this.getPropertyModuleExport(exportNode)
} else {
exportNode = ast.body.find(
node => node.type === 'ExportDefaultDeclaration'
)
if (!exportNode) throw 'Unable to find default export'
var property = this.getPropertyExportDefault(exportNode)
// 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])
}
if (property) {
switch (this.staticSiteConfig.type) {
case 'nuxt':
this.parseNuxt(property)
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)
// 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])
}
}
return propertyNode
}
parseNuxt(propertyNode) {
// Find the base node
if (propertyNode && propertyNode.value.type === 'ObjectExpression') {
var baseNode = propertyNode.value.properties.find(
node =>
node.key.type === 'Identifier' &&
node.key.name === this.staticSiteConfig.subPathName
) //'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])
}
// 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])
}
}
parseNextGatsby(pathNode) {
if (pathNode) {
this.config =
this.config.slice(0, pathNode.value.range[0]) +
`'${this.staticSiteConfig.newPath}'` +
this.config.slice(pathNode.value.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__) => {
const core = __nccwpck_require__(2186)
const axios = __nccwpck_require__(6545)
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}) {
try {
switch (staticSiteGenerator) {
case 'nuxt':
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()
// Parse/mutate the configuration file
new ConfigParser(getParserConfiguration(staticSiteGenerator, path)).parse()
} catch (error) {
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.`,
@@ -14902,6 +14874,14 @@ async function setPagesPath({staticSiteGenerator, path}) {
module.exports = setPagesPath
/***/ }),
/***/ 9729:
/***/ ((module) => {
module.exports = eval("require")("prettier");
/***/ }),
/***/ 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.
@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
MIT
MIT License
@@ -572,24 +582,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
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
MIT
MIT License