Socket
Socket
Sign inDemoInstall

@swc/cli

Package Overview
Dependencies
Maintainers
1
Versions
70
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@swc/cli - npm Package Compare versions

Comparing version 0.1.53 to 0.1.54

12

lib/spack/index.js

@@ -17,3 +17,3 @@ "use strict";

function isUserDefinedEntry(name) {
if (typeof spackOptions.entry === 'string') {
if (typeof spackOptions.entry === "string") {
return spackOptions.entry === name;

@@ -40,5 +40,5 @@ }

await Object.keys(output).map(async (name)=>{
let fullPath = '';
let fullPath = "";
if (isUserDefinedEntry(name)) {
fullPath = (0, _path).join(spackOptions.output.path, spackOptions.output.name.replace('[name]', name));
fullPath = (0, _path).join(spackOptions.output.path, spackOptions.output.name.replace("[name]", name));
} else {

@@ -53,9 +53,9 @@ const ext = (0, _path).extname(name);

});
await write(fullPath, output[name].code, 'utf-8');
await write(fullPath, output[name].code, "utf-8");
if (output[name].map) {
await write(`${fullPath}.map`, output[name].map, 'utf-8');
await write(`${fullPath}.map`, output[name].map, "utf-8");
}
});
} else {
throw new Error('Cannot print to stdout: not implemented yet');
throw new Error("Cannot print to stdout: not implemented yet");
}

@@ -62,0 +62,0 @@ const emitEnd = process.hrtime(emitStart);

@@ -43,6 +43,6 @@ "use strict";

_commander.default.option("--target [browser | node]", "Target runtime environment");
_commander.default.option('--context [path]', `The base directory (absolute path!) for resolving the 'entry'` + ` option. If 'output.pathinfo' is set, the included pathinfo is shortened to this directory`, 'The current directory');
_commander.default.option('--entry [list]', "List of entries", collect);
_commander.default.option("--context [path]", `The base directory (absolute path!) for resolving the 'entry'` + ` option. If 'output.pathinfo' is set, the included pathinfo is shortened to this directory`, "The current directory");
_commander.default.option("--entry [list]", "List of entries", collect);
// commander.option('-W --watch', `Enter watch mode, which rebuilds on file change.`)
_commander.default.option('--debug', `Switch loaders to debug mode`);
_commander.default.option("--debug", `Switch loaders to debug mode`);
// commander.option('--devtool', `Select a developer tool to enhance debugging.`)

@@ -58,4 +58,4 @@ // -d shortcut for --debug --devtool eval-cheap-module-source-map

// Output options:
_commander.default.option('-o --output', `The output path and file for compilation assets`);
_commander.default.option('--output-path', `The output directory as **absolute path**`);
_commander.default.option("-o --output", `The output path and file for compilation assets`);
_commander.default.option("--output-path", `The output directory as **absolute path**`);
// --output-filename Specifies the name of each output file on disk.

@@ -179,3 +179,3 @@ // You must **not** specify an absolute path here!

var _config;
const configOpts = await (0, _spack).compileBundleOptions((_config = opts.config) !== null && _config !== void 0 ? _config : path.resolve('spack.config.js'));
const configOpts = await (0, _spack).compileBundleOptions((_config = opts.config) !== null && _config !== void 0 ? _config : path.resolve("spack.config.js"));
if (opts.entry) {

@@ -196,7 +196,7 @@ configOpts.entry = opts.entry;

var _outputPath;
configOpts.output.path = (_outputPath = opts.outputPath) !== null && _outputPath !== void 0 ? _outputPath : '[name].js';
configOpts.output.path = (_outputPath = opts.outputPath) !== null && _outputPath !== void 0 ? _outputPath : "[name].js";
}
if (!configOpts.output.name) {
var _output;
configOpts.output.name = (_output = opts.output) !== null && _output !== void 0 ? _output : '[name].js';
configOpts.output.name = (_output = opts.output) !== null && _output !== void 0 ? _output : "[name].js";
}

@@ -203,0 +203,0 @@ // if (!configOpts.output.name) {

@@ -7,3 +7,3 @@ "use strict";

exports.default = void 0;
const fsMock = jest.createMockFromModule('fs');
const fsMock = jest.createMockFromModule("fs");
let mockStats = {

@@ -10,0 +10,0 @@ };

@@ -5,8 +5,8 @@ "use strict";

jest.mock("@swc/core");
describe('compile', ()=>{
describe("compile", ()=>{
it("compile with sync transform", async ()=>{
const options = {
};
await (0, _compile).compile('test.ts', options, true, undefined);
expect(_core.transformFileSync).toHaveBeenCalledWith('test.ts', options);
await (0, _compile).compile("test.ts", options, true, undefined);
expect(_core.transformFileSync).toHaveBeenCalledWith("test.ts", options);
});

@@ -16,5 +16,5 @@ it("compile with async transform", async ()=>{

};
await (0, _compile).compile('test.ts', options, false, undefined);
expect(_core.transformFile).toHaveBeenCalledWith('test.ts', options);
await (0, _compile).compile("test.ts", options, false, undefined);
expect(_core.transformFile).toHaveBeenCalledWith("test.ts", options);
});
});

@@ -33,6 +33,6 @@ "use strict";

const createDefaultResult = ()=>({
"cliOptions": {
"copyFiles": false,
"deleteDirOnStart": false,
"extensions": [
cliOptions: {
copyFiles: false,
deleteDirOnStart: false,
extensions: [
".js",

@@ -47,31 +47,31 @@ ".jsx",

// @ts-expect-error
"filename": undefined,
"filenames": [
filename: undefined,
filenames: [
"src"
],
"includeDotfiles": false,
includeDotfiles: false,
// @ts-expect-error
"outDir": undefined,
outDir: undefined,
// @ts-expect-error
"outFile": undefined,
"quiet": false,
"sourceMapTarget": undefined,
"sync": false,
"watch": false
outFile: undefined,
quiet: false,
sourceMapTarget: undefined,
sync: false,
watch: false
},
"swcOptions": {
"configFile": undefined,
"jsc": {
"parser": undefined,
"transform": {
swcOptions: {
configFile: undefined,
jsc: {
parser: undefined,
transform: {
}
},
"sourceFileName": undefined,
"sourceMaps": undefined,
"sourceRoot": undefined,
"swcrc": true
sourceFileName: undefined,
sourceMaps: undefined,
sourceRoot: undefined,
swcrc: true
}
})
;
describe('parserArgs', ()=>{
describe("parserArgs", ()=>{
let defaultResult;

@@ -84,5 +84,5 @@ beforeEach(()=>{

const args = [
'node',
'/path/to/node_modules/swc-cli/bin/swc.js',
'src'
"node",
"/path/to/node_modules/swc-cli/bin/swc.js",
"src"
];

@@ -92,3 +92,3 @@ const result = await (0, _options).default(args);

});
describe('errors', ()=>{
describe("errors", ()=>{
let mockExit;

@@ -98,5 +98,5 @@ let mockConsoleError;

//@ts-expect-error
mockExit = jest.spyOn(process, 'exit').mockImplementation(()=>{
mockExit = jest.spyOn(process, "exit").mockImplementation(()=>{
});
mockConsoleError = jest.spyOn(console, 'error').mockImplementation(()=>{
mockConsoleError = jest.spyOn(console, "error").mockImplementation(()=>{
});

@@ -112,6 +112,6 @@ });

});
it('exits without filenames', async ()=>{
it("exits without filenames", async ()=>{
const args = [
'node',
'/path/to/node_modules/swc-cli/bin/swc.js',
"node",
"/path/to/node_modules/swc-cli/bin/swc.js"
];

@@ -122,8 +122,8 @@ await (0, _options).default(args);

});
it('--watch exits without --out-dir', async ()=>{
it("--watch exits without --out-dir", async ()=>{
const args = [
'node',
'/path/to/node_modules/swc-cli/bin/swc.js',
'src',
'--watch',
"node",
"/path/to/node_modules/swc-cli/bin/swc.js",
"src",
"--watch",
];

@@ -134,9 +134,9 @@ await (0, _options).default(args);

});
it('--watch exits without filenames', async ()=>{
it("--watch exits without filenames", async ()=>{
const args = [
'node',
'/path/to/node_modules/swc-cli/bin/swc.js',
'--watch',
'--out-dir',
'esm'
"node",
"/path/to/node_modules/swc-cli/bin/swc.js",
"--watch",
"--out-dir",
"esm",
];

@@ -147,11 +147,11 @@ await (0, _options).default(args);

});
it('--out-dir exits with conflicting -out-file', async ()=>{
it("--out-dir exits with conflicting -out-file", async ()=>{
const args = [
'node',
'/path/to/node_modules/swc-cli/bin/swc.js',
'src',
'--out-file',
'esm/index.js',
'--out-dir',
'esm'
"node",
"/path/to/node_modules/swc-cli/bin/swc.js",
"src",
"--out-file",
"esm/index.js",
"--out-dir",
"esm",
];

@@ -163,9 +163,9 @@ await (0, _options).default(args);

});
describe('--source-maps', ()=>{
describe("--source-maps", ()=>{
it("source maps is ambiguous", async ()=>{
const args = [
'node',
'/path/to/node_modules/swc-cli/bin/swc.js',
'src',
'--source-maps'
"node",
"/path/to/node_modules/swc-cli/bin/swc.js",
"src",
"--source-maps",
];

@@ -182,7 +182,7 @@ const result = await (0, _options).default(args);

const args = [
'node',
'/path/to/node_modules/swc-cli/bin/swc.js',
'--source-maps',
'true',
'src'
"node",
"/path/to/node_modules/swc-cli/bin/swc.js",
"--source-maps",
"true",
"src",
];

@@ -199,7 +199,7 @@ const result = await (0, _options).default(args);

const args = [
'node',
'/path/to/node_modules/swc-cli/bin/swc.js',
'-s',
'inline',
'src'
"node",
"/path/to/node_modules/swc-cli/bin/swc.js",
"-s",
"inline",
"src",
];

@@ -209,3 +209,3 @@ const result = await (0, _options).default(args);

swcOptions: {
sourceMaps: 'inline'
sourceMaps: "inline"
}

@@ -216,9 +216,9 @@ });

});
describe('--config', ()=>{
describe("--config", ()=>{
it("throws with no config", async ()=>{
const args = [
'node',
'/path/to/node_modules/swc-cli/bin/swc.js',
'src',
'-C',
"node",
"/path/to/node_modules/swc-cli/bin/swc.js",
"src",
"-C",
];

@@ -230,7 +230,7 @@ expect(()=>(0, _options).default(args)

const args = [
'node',
'/path/to/node_modules/swc-cli/bin/swc.js',
'--config',
'jsc.transform.react.development=true',
'src'
"node",
"/path/to/node_modules/swc-cli/bin/swc.js",
"--config",
"jsc.transform.react.development=true",
"src",
];

@@ -251,9 +251,9 @@ const result = await (0, _options).default(args);

const args = [
'node',
'/path/to/node_modules/swc-cli/bin/swc.js',
'--config',
'jsc.transform.react.development=true',
'-C',
'module.type=commonjs',
'src'
"node",
"/path/to/node_modules/swc-cli/bin/swc.js",
"--config",
"jsc.transform.react.development=true",
"-C",
"module.type=commonjs",
"src",
];

@@ -270,3 +270,3 @@ const result = await (0, _options).default(args);

module: {
type: 'commonjs'
type: "commonjs"
}

@@ -278,7 +278,7 @@ });

const args = [
'node',
'/path/to/node_modules/swc-cli/bin/swc.js',
'--config',
'jsc.transform.react.development=true,module.type=commonjs',
'src'
"node",
"/path/to/node_modules/swc-cli/bin/swc.js",
"--config",
"jsc.transform.react.development=true,module.type=commonjs",
"src",
];

@@ -295,3 +295,3 @@ const result = await (0, _options).default(args);

module: {
type: 'commonjs'
type: "commonjs"
}

@@ -303,7 +303,7 @@ });

const args = [
'node',
'/path/to/node_modules/swc-cli/bin/swc.js',
'--config',
'no_equals',
'src'
"node",
"/path/to/node_modules/swc-cli/bin/swc.js",
"--config",
"no_equals",
"src",
];

@@ -310,0 +310,0 @@ const result = await (0, _options).default(args);

@@ -10,5 +10,5 @@ "use strict";

}
jest.mock('fs');
jest.mock('fast-glob');
describe('globSources', ()=>{
jest.mock("fs");
jest.mock("fast-glob");
describe("globSources", ()=>{
beforeEach(()=>{

@@ -51,3 +51,3 @@ _fs.default.resetMockStats();

_fs.default.setMockStats({
"file": {
file: {
isDirectory: ()=>false

@@ -65,3 +65,3 @@ }

]).toEqual([
'.dotfile',
".dotfile",
"file"

@@ -77,3 +77,3 @@ ]);

_fs.default.setMockStats({
"file": new Error('Failed stat')
file: new Error("Failed stat")
});

@@ -89,3 +89,3 @@ const files = await (0, _sources).globSources([

]).toEqual([
'.dotfile'
".dotfile"
]);

@@ -95,3 +95,3 @@ });

_fs.default.setMockStats({
"directory": {
directory: {
isDirectory: ()=>true

@@ -101,3 +101,3 @@ }

_fs.default.setMockStats({
"file": {
file: {
isDirectory: ()=>false

@@ -126,3 +126,3 @@ }

_fs.default.setMockStats({
"directory": {
directory: {
isDirectory: ()=>true

@@ -132,3 +132,3 @@ }

_fs.default.setMockStats({
"file": {
file: {
isDirectory: ()=>false

@@ -147,3 +147,3 @@ }

]).toEqual([
"file",
"file"
]);

@@ -173,3 +173,3 @@ });

]).toEqual([
"index.js",
"index.js"
]);

@@ -199,3 +199,3 @@ });

]).toEqual([
"index.spec.js",
"index.spec.js"
]);

@@ -205,3 +205,3 @@ });

_fs.default.setMockStats({
"src": {
src: {
isDirectory: ()=>true

@@ -222,3 +222,3 @@ }

"src/index.js",
"src/index.spec.js"
"src/index.spec.js",
]);

@@ -235,11 +235,11 @@ const files = await (0, _sources).globSources([

]).toEqual([
"src/index.spec.js",
"src/index.spec.js"
]);
});
});
describe('slitCompilableAndCopyable', ()=>{
describe("slitCompilableAndCopyable", ()=>{
const extensions = [
".ts"
];
it('separate compilable and copyable when copyFiles=true', ()=>{
it("separate compilable and copyable when copyFiles=true", ()=>{
const files = [

@@ -257,3 +257,3 @@ "test.ts",

});
it('separate compilable and copyable when copyFiles=false', ()=>{
it("separate compilable and copyable when copyFiles=false", ()=>{
const files = [

@@ -260,0 +260,0 @@ "test.ts",

@@ -26,6 +26,6 @@ "use strict";

if (options.sourceFileName) {
sourceMap['sources'][0] = options.sourceFileName;
sourceMap["sources"][0] = options.sourceFileName;
}
if (options.sourceRoot) {
sourceMap['sourceRoot'] = options.sourceRoot;
sourceMap["sourceRoot"] = options.sourceRoot;
}

@@ -59,3 +59,3 @@ output.map = JSON.stringify(sourceMap);

mode
})
}),
]);

@@ -62,0 +62,0 @@ }

@@ -18,3 +18,3 @@ "use strict";

}
const { mkdir , rmdir , rm , copyFile , unlink , } = _fs.promises;
const { mkdir , rmdir , rm , copyFile , unlink } = _fs.promises;
const cwd = process.cwd();

@@ -27,10 +27,10 @@ const recursive = {

*/ function stripComponents(filename) {
const components = filename.split('/').slice(1);
const components = filename.split("/").slice(1);
if (!components.length) {
return filename;
}
while(components[0] === '..'){
while(components[0] === ".."){
components.shift();
}
return components.join('/');
return components.join("/");
}

@@ -78,3 +78,3 @@ function getDest(filename, outDir, ext) {

async function initialCompilation(cliOptions, swcOptions) {
const { filenames , copyFiles , extensions , outDir , sync , quiet , watch , } = cliOptions;
const { filenames , copyFiles , extensions , outDir , sync , quiet , watch } = cliOptions;
const results = new Map();

@@ -111,3 +111,3 @@ const start = process.hrtime();

Promise.allSettled(copyable.map((file)=>handleCopy(file, outDir)
))
)),
]).then(([compiled, copied])=>{

@@ -152,3 +152,3 @@ compiled.forEach((result, index)=>{

if (compiled) {
message += `Successfully compiled: ${compiled} ${compiled > 1 ? 'files' : 'file'}`;
message += `Successfully compiled: ${compiled} ${compiled > 1 ? "files" : "file"}`;
}

@@ -159,3 +159,3 @@ if (compiled && copied) {

if (copied) {
message += `copied ${copied} ${copied > 1 ? 'files' : 'file'}`;
message += `copied ${copied} ${copied > 1 ? "files" : "file"}`;
}

@@ -173,10 +173,10 @@ message += ` with swc (%dms)`;

async function watchCompilation(cliOptions, swcOptions) {
const { filenames , copyFiles , extensions , outDir , quiet , sync , } = cliOptions;
const { filenames , copyFiles , extensions , outDir , quiet , sync } = cliOptions;
const watcher = await (0, _sources).watchSources(filenames, cliOptions);
watcher.on('ready', ()=>{
watcher.on("ready", ()=>{
if (!quiet) {
console.info('Watching for file changes.');
console.info("Watching for file changes.");
}
});
watcher.on('unlink', async (filename)=>{
watcher.on("unlink", async (filename)=>{
try {

@@ -189,3 +189,3 @@ if ((0, _sources).isCompilableExtension(filename, extensions)) {

} catch (err) {
if (err.code !== 'ENOENT') {
if (err.code !== "ENOENT") {
console.error(err.stack);

@@ -196,4 +196,4 @@ }

for (const type of [
'add',
'change'
"add",
"change"
]){

@@ -229,3 +229,3 @@ watcher.on(type, async (filename)=>{

async function dir({ cliOptions , swcOptions }) {
const { watch , } = cliOptions;
const { watch } = cliOptions;
await beforeStartCompilation(cliOptions);

@@ -232,0 +232,0 @@ await initialCompilation(cliOptions, swcOptions);

@@ -88,3 +88,3 @@ "use strict";

if (result.map) {
const map = `//#sourceMappingURL=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(result.map), 'utf8').toString('base64')}`;
const map = `//#sourceMappingURL=data:application/json;charset=utf-8;base64,${Buffer.from(JSON.stringify(result.map), "utf8").toString("base64")}`;
process.stdout.write(map);

@@ -127,3 +127,3 @@ }

const watcher = await (0, _sources).watchSources(cliOptions.filenames, cliOptions);
watcher.on('ready', ()=>{
watcher.on("ready", ()=>{
Promise.resolve().then(async ()=>{

@@ -133,3 +133,3 @@ util.assertCompilationResult(results, cliOptions.quiet);

if (!cliOptions.quiet) {
console.info('Watching for file changes.');
console.info("Watching for file changes.");
}

@@ -136,0 +136,0 @@ }).catch((err)=>{

@@ -18,3 +18,3 @@ "use strict";

program = new _commander.default.Command();
/* istanbul ignore next */ if (process.env.NODE_ENV === 'test') {
/* istanbul ignore next */ if (process.env.NODE_ENV === "test") {
program.exitOverride();

@@ -120,3 +120,3 @@ }

let options = swcOptions;
const keyParts = key.split('.');
const keyParts = key.split(".");
const lastIndex = keyParts.length - 1;

@@ -123,0 +123,0 @@ for (const [index, keyPart] of keyParts.entries()){

@@ -45,3 +45,3 @@ "use strict";

}) {
const { includeDotfiles =false , ignorePatterns =[] , onlyPatterns =[] } = options;
const { includeDotfiles =false , ignorePatterns =[] , onlyPatterns =[] , } = options;
const globConfig = {

@@ -102,3 +102,3 @@ dot: includeDotfiles,

const { default: chokidar } = await Promise.resolve().then(function() {
return _interopRequireWildcard(require('chokidar'));
return _interopRequireWildcard(require("chokidar"));
});

@@ -113,3 +113,3 @@ return chokidar;

}) {
const { includeDotfiles =false , ignorePatterns =[] , onlyPatterns =[] } = options;
const { includeDotfiles =false , ignorePatterns =[] , onlyPatterns =[] , } = options;
const globConfig = {

@@ -116,0 +116,0 @@ dot: includeDotfiles

@@ -68,6 +68,6 @@ "use strict";

if (opts.sourceFileName) {
sourceMap['sources'][0] = opts.sourceFileName;
sourceMap["sources"][0] = opts.sourceFileName;
}
if (opts.sourceRoot) {
sourceMap['sourceRoot'] = opts.sourceRoot;
sourceMap["sourceRoot"] = opts.sourceRoot;
}

@@ -105,3 +105,3 @@ result.map = JSON.stringify(sourceMap);

failed++;
} else if (value === 'copied') {
} else if (value === "copied") {
copied++;

@@ -108,0 +108,0 @@ } else if (value) {

{
"name": "@swc/cli",
"version": "0.1.53",
"version": "0.1.54",
"description": "CLI for the swc project",

@@ -12,5 +12,9 @@ "main": "lib/swc/index.js",

"build:watch": "swc src -d lib --watch --ignore '**/*.test.ts' --ignore '**/__mocks__/**'",
"format:src": "prettier --write src",
"format:examples": "prettier --write examples",
"format": "yarn format:src && yarn format:examples",
"test": "jest",
"test:watch": "jest --watch",
"test:coverage": "JEST_COVERAGE=true jest --coverage"
"test:coverage": "JEST_COVERAGE=true jest --coverage",
"enableGitHooks": "simple-git-hooks"
},

@@ -61,2 +65,5 @@ "repository": {

"jest": "^27.0.3",
"nano-staged": "^0.4.5",
"prettier": "^2.5.1",
"simple-git-hooks": "^2.7.0",
"ts-jest": "^27.0.4",

@@ -63,0 +70,0 @@ "typescript": "~4.3.2"

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc