Comparing version 0.1.46 to 0.1.48
@@ -35,3 +35,3 @@ "use strict"; | ||
const bundleEnd = process.hrtime(bundleStart); | ||
console.info(`Bindling done: ${bundleEnd[0]}s ${bundleEnd[1] / 1000000}ms`); | ||
console.info(`Bundling done: ${bundleEnd[0]}s ${bundleEnd[1] / 1000000}ms`); | ||
const emitStart = process.hrtime(); | ||
@@ -38,0 +38,0 @@ if ((ref = spackOptions.output) === null || ref === void 0 ? void 0 : ref.path) { |
@@ -165,3 +165,4 @@ "use strict"; | ||
// --json, -j Prints the result as JSON. [boolean] | ||
_commander.default.version(`@swc/cli: ${pkg.version}\n@swc/core: ${_core.version}`); | ||
_commander.default.version(`@swc/cli: ${pkg.version} | ||
@swc/core: ${_core.version}`); | ||
async function parseSpackArgs(args) { | ||
@@ -168,0 +169,0 @@ // |
@@ -9,3 +9,3 @@ "use strict"; | ||
}; | ||
await (0, _compile).compile('test.ts', options, true); | ||
await (0, _compile).compile('test.ts', options, true, undefined); | ||
expect(_core.transformFileSync).toHaveBeenCalledWith('test.ts', options); | ||
@@ -16,5 +16,5 @@ }); | ||
}; | ||
await (0, _compile).compile('test.ts', options, false); | ||
await (0, _compile).compile('test.ts', options, false, undefined); | ||
expect(_core.transformFile).toHaveBeenCalledWith('test.ts', options); | ||
}); | ||
}); |
@@ -62,5 +62,11 @@ "use strict"; | ||
} | ||
async function compile(filename, opts, sync) { | ||
async function compile(filename, opts, sync, outputPath) { | ||
const options = { | ||
...opts | ||
}; | ||
if (outputPath) { | ||
options.outputPath = outputPath; | ||
} | ||
try { | ||
const result = sync ? (0, _core).transformFileSync(filename, opts) : await (0, _core).transformFile(filename, opts); | ||
const result = sync ? (0, _core).transformFileSync(filename, options) : await (0, _core).transformFile(filename, options); | ||
return result; | ||
@@ -67,0 +73,0 @@ } catch (err) { |
@@ -50,3 +50,3 @@ "use strict"; | ||
}; | ||
const result = await (0, _util).compile(filename, options, sync); | ||
const result = await (0, _util).compile(filename, options, sync, dest); | ||
if (result) { | ||
@@ -53,0 +53,0 @@ await (0, _compile).outputResult(result, filename, dest, options); |
@@ -5,2 +5,3 @@ "use strict"; | ||
}); | ||
exports.default = _default; | ||
var _path = _interopRequireDefault(require("path")); | ||
@@ -102,7 +103,7 @@ var _slash = _interopRequireDefault(require("slash")); | ||
sourceMaps: Boolean(swcOptions.sourceMaps) | ||
}, cliOptions.sync); | ||
}, cliOptions.sync, cliOptions.outFile); | ||
} | ||
async function getProgram(previousResults = new Map()) { | ||
const results = new Map(); | ||
for (const filename of await (0, _sources).globSources(cliOptions.filenames, cliOptions.includeDotfiles)){ | ||
for (const filename of (await (0, _sources).globSources(cliOptions.filenames, cliOptions.includeDotfiles))){ | ||
if ((0, _sources).isCompilableExtension(filename, cliOptions.extensions)) { | ||
@@ -193,3 +194,3 @@ results.set(filename, previousResults.get(filename)); | ||
sourceFileName: "stdin" | ||
}, cliOptions.sync); | ||
}, cliOptions.sync, undefined); | ||
output([ | ||
@@ -205,2 +206,1 @@ res | ||
} | ||
exports.default = _default; |
"use strict"; | ||
var _dir = _interopRequireDefault(require("./dir")); | ||
var _file = _interopRequireDefault(require("./file")); | ||
var _options = _interopRequireDefault(require("./options")); | ||
var _options = _interopRequireWildcard(require("./options")); | ||
function _interopRequireDefault(obj) { | ||
@@ -10,2 +10,26 @@ return obj && obj.__esModule ? obj : { | ||
} | ||
function _interopRequireWildcard(obj) { | ||
if (obj && obj.__esModule) { | ||
return obj; | ||
} else { | ||
var newObj = { | ||
}; | ||
if (obj != null) { | ||
for(var key in obj){ | ||
if (Object.prototype.hasOwnProperty.call(obj, key)) { | ||
var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : { | ||
}; | ||
if (desc.get || desc.set) { | ||
Object.defineProperty(newObj, key, desc); | ||
} else { | ||
newObj[key] = obj[key]; | ||
} | ||
} | ||
} | ||
} | ||
newObj.default = obj; | ||
return newObj; | ||
} | ||
} | ||
(0, _options).initProgram(); | ||
const opts = (0, _options).default(process.argv); | ||
@@ -12,0 +36,0 @@ const fn = opts.cliOptions.outDir ? _dir.default : _file.default; |
@@ -6,2 +6,3 @@ "use strict"; | ||
exports.default = parserArgs; | ||
exports.initProgram = void 0; | ||
var _commander = _interopRequireDefault(require("commander")); | ||
@@ -15,25 +16,36 @@ var _core = require("@swc/core"); | ||
const pkg = require("../../package.json"); | ||
_commander.default.option("-f, --filename [filename]", "filename to use when reading from stdin - this will be used in source-maps, errors etc"); | ||
_commander.default.option("--config-file [path]", "Path to a .swcrc file to use"); | ||
_commander.default.option("--env-name [name]", "The name of the 'env' to use when loading configs and plugins. " + "Defaults to the value of SWC_ENV, or else NODE_ENV, or else 'development'."); | ||
_commander.default.option("--no-swcrc", "Whether or not to look up .swcrc files"); | ||
_commander.default.option("--delete-dir-on-start", "Whether or not delete output directory on start"); | ||
_commander.default.option("--ignore [list]", "list of glob paths to **not** compile", collect); | ||
_commander.default.option("--only [list]", "list of glob paths to **only** compile", collect); | ||
_commander.default.option("-w, --watch", "Recompile files on changes"); | ||
_commander.default.option("-q, --quiet", "Suppress compilation output"); | ||
_commander.default.option("-s, --source-maps [true|false|inline|both]", "generate source maps", unstringify); | ||
_commander.default.option("--source-map-target [string]", "set `file` on returned source map"); | ||
_commander.default.option("--source-file-name [string]", "set `sources[0]` on returned source map"); | ||
_commander.default.option("--source-root [filename]", "the root from which all sources are relative"); | ||
_commander.default.option("-o, --out-file [out]", "Compile all input files into a single file"); | ||
_commander.default.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory"); | ||
_commander.default.option("-D, --copy-files", "When compiling a directory copy over non-compilable files"); | ||
_commander.default.option("--include-dotfiles", "Include dotfiles when compiling and copying non-compilable files"); | ||
_commander.default.option("-C, --config <config>", "Override a config from .swcrc file. e.g. -C module.type=amd -C module.moduleId=hello", collect); | ||
_commander.default.option("--sync", "Invoke swc synchronously. Useful for debugging.", collect); | ||
_commander.default.option("--log-watch-compilation", "Log a message when a watched file is successfully compiled", true); | ||
_commander.default.option("--extensions [list]", "Use specific extensions", collect); | ||
_commander.default.version(`\n@swc/cli: ${pkg.version}\n@swc/core: ${_core.version}\n`); | ||
_commander.default.usage("[options] <files ...>"); | ||
let program; | ||
const initProgram = ()=>{ | ||
program = new _commander.default.Command(); | ||
/* istanbul ignore next */ if (process.env.NODE_ENV === 'test') { | ||
program.exitOverride(); | ||
} | ||
program.option("-f, --filename [filename]", "filename to use when reading from stdin - this will be used in source-maps, errors etc"); | ||
program.option("--config-file [path]", "Path to a .swcrc file to use"); | ||
program.option("--env-name [name]", "The name of the 'env' to use when loading configs and plugins. " + "Defaults to the value of SWC_ENV, or else NODE_ENV, or else 'development'."); | ||
program.option("--no-swcrc", "Whether or not to look up .swcrc files"); | ||
program.option("--delete-dir-on-start", "Whether or not delete output directory on start"); | ||
program.option("--ignore [list]", "list of glob paths to **not** compile", collect); | ||
program.option("--only [list]", "list of glob paths to **only** compile", collect); | ||
program.option("-w, --watch", "Recompile files on changes"); | ||
program.option("-q, --quiet", "Suppress compilation output"); | ||
program.option("-s, --source-maps [true|false|inline|both]", "generate source maps", unstringify); | ||
program.option("--source-map-target [string]", "set `file` on returned source map"); | ||
program.option("--source-file-name [string]", "set `sources[0]` on returned source map"); | ||
program.option("--source-root [filename]", "the root from which all sources are relative"); | ||
program.option("-o, --out-file [out]", "Compile all input files into a single file"); | ||
program.option("-d, --out-dir [out]", "Compile an input directory of modules into an output directory"); | ||
program.option("-D, --copy-files", "When compiling a directory copy over non-compilable files"); | ||
program.option("--include-dotfiles", "Include dotfiles when compiling and copying non-compilable files"); | ||
program.option("-C, --config <config>", "Override a config from .swcrc file. e.g. -C module.type=amd -C module.moduleId=hello", collect); | ||
program.option("--sync", "Invoke swc synchronously. Useful for debugging.", collect); | ||
program.option("--log-watch-compilation", "Log a message when a watched file is successfully compiled", true); | ||
program.option("--extensions [list]", "Use specific extensions", collect); | ||
program.version(` | ||
@swc/cli: ${pkg.version} | ||
@swc/core: ${_core.version} | ||
`); | ||
program.usage("[options] <files ...>"); | ||
}; | ||
exports.initProgram = initProgram; | ||
function unstringify(val) { | ||
@@ -48,3 +60,3 @@ try { | ||
// If the user passed the option with no value, like "babel file.js --presets", do nothing. | ||
if (typeof value !== "string") return previousValue; | ||
/* istanbul ignore next */ if (typeof value !== "string") return previousValue; | ||
const values = value.split(","); | ||
@@ -54,5 +66,5 @@ return previousValue ? previousValue.concat(values) : values; | ||
function parserArgs(args) { | ||
_commander.default.parse(args); | ||
const opts = _commander.default.opts(); | ||
const filenames = _commander.default.args; | ||
program.parse(args); | ||
const opts = program.opts(); | ||
const filenames = program.args; | ||
const errors = []; | ||
@@ -107,4 +119,17 @@ if (opts.outDir && !filenames.length) { | ||
} | ||
//@ts-expect-error | ||
swcOptions[key] = value; | ||
// https://github.com/swc-project/cli/issues/45 | ||
let options = swcOptions; | ||
const keyParts = key.split('.'); | ||
const lastIndex = keyParts.length - 1; | ||
for (const [index, keyPart] of keyParts.entries()){ | ||
if (options[keyPart] === undefined && index !== lastIndex) { | ||
options[keyPart] = { | ||
}; | ||
} | ||
if (index === lastIndex) { | ||
options[keyPart] = value; | ||
} else { | ||
options = options[keyPart]; | ||
} | ||
} | ||
} | ||
@@ -111,0 +136,0 @@ } |
@@ -41,3 +41,3 @@ "use strict"; | ||
} | ||
async function transform(filename, code, opts, sync) { | ||
async function transform(filename, code, opts, sync, outputPath) { | ||
opts = { | ||
@@ -47,2 +47,5 @@ filename, | ||
}; | ||
if (outputPath) { | ||
opts.outputPath = outputPath; | ||
} | ||
if (sync) { | ||
@@ -53,6 +56,9 @@ return swc.transformSync(code, opts); | ||
} | ||
async function compile(filename, opts, sync) { | ||
async function compile(filename, opts, sync, outputPath) { | ||
opts = { | ||
...opts | ||
}; | ||
if (outputPath) { | ||
opts.outputPath = outputPath; | ||
} | ||
try { | ||
@@ -59,0 +65,0 @@ const result = sync ? swc.transformFileSync(filename, opts) : await swc.transformFile(filename, opts); |
{ | ||
"name": "@swc/cli", | ||
"version": "0.1.46", | ||
"version": "0.1.48", | ||
"description": "CLI for the swc project", | ||
@@ -13,3 +13,4 @@ "main": "lib/swc/index.js", | ||
"test": "jest", | ||
"test:watch": "jest --watch" | ||
"test:watch": "jest --watch", | ||
"test:coverage": "JEST_COVERAGE=true jest --coverage" | ||
}, | ||
@@ -51,3 +52,3 @@ "repository": { | ||
"@swc/cli": "^0.1.43", | ||
"@swc/core": "^1.2.4", | ||
"@swc/core": "^1.2.66", | ||
"@swc/jest": "^0.1.2", | ||
@@ -57,7 +58,9 @@ "@types/jest": "^26.0.23", | ||
"chokidar": "^3.5.1", | ||
"deepmerge": "^4.2.2", | ||
"jest": "^27.0.3", | ||
"ts-jest": "^27.0.4", | ||
"typescript": "~4.3.2" | ||
}, | ||
"peerDependencies": { | ||
"@swc/core": "^1.2.4", | ||
"@swc/core": "^1.2.66", | ||
"chokidar": "^3.5.1" | ||
@@ -64,0 +67,0 @@ }, |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
66897
1722
10