Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@swc/cli

Package Overview
Dependencies
Maintainers
1
Versions
71
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.61 to 0.1.62

37

lib/spack/index.js
"use strict";
var _core = require("@swc/core");
var _fs = require("fs");
var _path = require("path");
var _util = require("util");
var _options = _interopRequireDefault(require("./options"));
Object.defineProperty(exports, "__esModule", {
value: true
});
const _core = require("@swc/core");
const _fs = require("fs");
const _path = require("path");
const _util = require("util");
const _options = /*#__PURE__*/ _interopRequireDefault(require("./options"));
function _interopRequireDefault(obj) {

@@ -12,6 +15,6 @@ return obj && obj.__esModule ? obj : {

}
const write = (0, _util).promisify(_fs.writeFile);
const makeDir = (0, _util).promisify(_fs.mkdir);
const write = (0, _util.promisify)(_fs.writeFile);
const makeDir = (0, _util.promisify)(_fs.mkdir);
(async ()=>{
const { spackOptions } = await (0, _options).default(process.argv);
const { spackOptions } = await (0, _options.default)(process.argv);
function isUserDefinedEntry(name) {

@@ -32,20 +35,20 @@ if (typeof spackOptions.entry === 'string') {

async function build() {
var ref;
var _spackOptions_output;
const bundleStart = process.hrtime();
const output = await (0, _core).bundle(spackOptions);
const output = await (0, _core.bundle)(spackOptions);
const bundleEnd = process.hrtime(bundleStart);
console.info(`Bundling done: ${bundleEnd[0]}s ${bundleEnd[1] / 1000000}ms`);
const emitStart = process.hrtime();
if ((ref = spackOptions.output) === null || ref === void 0 ? void 0 : ref.path) {
if ((_spackOptions_output = spackOptions.output) === null || _spackOptions_output === void 0 ? void 0 : _spackOptions_output.path) {
await Object.keys(output).map(async (name)=>{
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 {
const ext = (0, _path).extname(name);
const base = (0, _path).basename(name, ext);
const filename = (0, _path).relative(process.cwd(), name);
fullPath = (0, _path).join(spackOptions.output.path, (0, _path).dirname(filename), `${base}.js`);
const ext = (0, _path.extname)(name);
const base = (0, _path.basename)(name, ext);
const filename = (0, _path.relative)(process.cwd(), name);
fullPath = (0, _path.join)(spackOptions.output.path, (0, _path.dirname)(filename), `${base}.js`);
}
await makeDir((0, _path).dirname(fullPath), {
await makeDir((0, _path.dirname)(fullPath), {
recursive: true

@@ -52,0 +55,0 @@ });

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

});
exports.default = parseSpackArgs;
var _core = require("@swc/core");
var _spack = require("@swc/core/spack");
var _commander = _interopRequireDefault(require("commander"));
var path = _interopRequireWildcard(require("path"));
async function parseSpackArgs(args) {
//
const cmd = _commander.default.parse(args);
const opts = cmd.opts();
const cliOptions = {
// watch: !!opts.watch,
debug: !!opts.debug
};
var _config;
const configOpts = await (0, _spack).compileBundleOptions((_config = opts.config) !== null && _config !== void 0 ? _config : path.resolve('spack.config.js'));
if (opts.entry) {
configOpts.entry = opts.entry;
}
if (opts.mode) {
configOpts.mode = opts.mode;
}
if (opts.target) {
configOpts.target = opts.target;
}
if (!configOpts.output) {
configOpts.output = {};
}
if (!configOpts.output.path) {
var _outputPath;
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';
}
// if (!configOpts.output.name) {
// configOpts.output.path = opts.outputPath;
// }
return {
cliOptions,
spackOptions: {
...configOpts
}
};
}
Object.defineProperty(exports, "default", {
enumerable: true,
get: ()=>parseSpackArgs
});
const _core = require("@swc/core");
const _spack = require("@swc/core/spack");
const _commander = /*#__PURE__*/ _interopRequireDefault(require("commander"));
const _path = /*#__PURE__*/ _interopRequireWildcard(require("path"));
function _interopRequireDefault(obj) {

@@ -56,22 +19,40 @@ return obj && obj.__esModule ? obj : {

}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interopRequireWildcard(obj, nodeInterop) {
if (!nodeInterop && 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];
}
}
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
newObj.default = obj;
return newObj;
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}

@@ -208,2 +189,42 @@ const pkg = require("../../package.json");

@swc/core: ${_core.version}`);
async function parseSpackArgs(args) {
//
const cmd = _commander.default.parse(args);
const opts = cmd.opts();
const cliOptions = {
// watch: !!opts.watch,
debug: !!opts.debug
};
var _opts_config;
const configOpts = await (0, _spack.compileBundleOptions)((_opts_config = opts.config) !== null && _opts_config !== void 0 ? _opts_config : _path.resolve('spack.config.js'));
if (opts.entry) {
configOpts.entry = opts.entry;
}
if (opts.mode) {
configOpts.mode = opts.mode;
}
if (opts.target) {
configOpts.target = opts.target;
}
if (!configOpts.output) {
configOpts.output = {};
}
if (!configOpts.output.path) {
var _opts_outputPath;
configOpts.output.path = (_opts_outputPath = opts.outputPath) !== null && _opts_outputPath !== void 0 ? _opts_outputPath : '[name].js';
}
if (!configOpts.output.name) {
var _opts_output;
configOpts.output.name = (_opts_output = opts.output) !== null && _opts_output !== void 0 ? _opts_output : '[name].js';
}
// if (!configOpts.output.name) {
// configOpts.output.path = opts.outputPath;
// }
return {
cliOptions,
spackOptions: {
...configOpts
}
};
}
function collect(value, previousValue) {

@@ -210,0 +231,0 @@ // If the user passed the option with no value, like "babel file.js --presets", do nothing.

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

});
exports.stat = stat;
exports.default = void 0;
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
stat: ()=>stat,
default: ()=>_default
});
const fsMock = jest.createMockFromModule('fs');
let mockStats = {};
function setMockStats(stats1) {
Object.entries(stats1).forEach(([path, stats])=>{
function setMockStats(stats) {
Object.entries(stats).forEach(([path, stats])=>{
mockStats[path] = stats;

@@ -29,5 +37,4 @@ });

fsMock.stat = stat;
var _default = fsMock;
exports.default = _default;
const _default = fsMock;
//# sourceMappingURL=fs.js.map
"use strict";
var _core = require("@swc/core");
var _compile = require("../compile");
Object.defineProperty(exports, "__esModule", {
value: true
});
const _core = require("@swc/core");
const _compile = require("../compile");
jest.mock("@swc/core");

@@ -8,3 +11,3 @@ describe('compile', ()=>{

const options = {};
await (0, _compile).compile('test.ts', options, true, undefined);
await (0, _compile.compile)('test.ts', options, true, undefined);
expect(_core.transformFileSync).toHaveBeenCalledWith('test.ts', options);

@@ -14,3 +17,3 @@ });

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

@@ -17,0 +20,0 @@ });

"use strict";
var _deepmerge = _interopRequireDefault(require("deepmerge"));
var _options = _interopRequireWildcard(require("../options"));
Object.defineProperty(exports, "__esModule", {
value: true
});
const _deepmerge = /*#__PURE__*/ _interopRequireDefault(require("deepmerge"));
const _options = /*#__PURE__*/ _interopRequireWildcard(require("../options"));
function _interopRequireDefault(obj) {

@@ -9,22 +12,40 @@ return obj && obj.__esModule ? obj : {

}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interopRequireWildcard(obj, nodeInterop) {
if (!nodeInterop && 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];
}
}
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
newObj.default = obj;
return newObj;
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}

@@ -70,4 +91,3 @@ const createDefaultResult = ()=>({

}
})
;
});
describe('parserArgs', ()=>{

@@ -77,3 +97,3 @@ let defaultResult;

defaultResult = createDefaultResult();
(0, _options).initProgram();
(0, _options.initProgram)();
});

@@ -86,3 +106,3 @@ it("minimal args returns default result", async ()=>{

];
const result = await (0, _options).default(args);
const result = await (0, _options.default)(args);
expect(result).toEqual(defaultResult);

@@ -109,5 +129,5 @@ });

'node',
'/path/to/node_modules/swc-cli/bin/swc.js',
'/path/to/node_modules/swc-cli/bin/swc.js'
];
await (0, _options).default(args);
await (0, _options.default)(args);
expect(mockExit).toHaveBeenCalledWith(2);

@@ -121,5 +141,5 @@ expect(mockConsoleError).toHaveBeenCalledTimes(2);

'src',
'--watch',
'--watch'
];
await (0, _options).default(args);
await (0, _options.default)(args);
expect(mockExit).toHaveBeenCalledWith(2);

@@ -136,3 +156,3 @@ expect(mockConsoleError).toHaveBeenCalledTimes(2);

];
await (0, _options).default(args);
await (0, _options.default)(args);
expect(mockExit).toHaveBeenCalledWith(2);

@@ -151,3 +171,3 @@ expect(mockConsoleError).toHaveBeenCalledTimes(3);

];
await (0, _options).default(args);
await (0, _options.default)(args);
expect(mockExit).toHaveBeenCalledWith(2);

@@ -165,4 +185,4 @@ expect(mockConsoleError).toHaveBeenCalledTimes(2);

];
const result = await (0, _options).default(args);
const expectedOptions = (0, _deepmerge).default(defaultResult, {
const result = await (0, _options.default)(args);
const expectedOptions = (0, _deepmerge.default)(defaultResult, {
swcOptions: {

@@ -182,4 +202,4 @@ sourceMaps: true

];
const result = await (0, _options).default(args);
const expectedOptions = (0, _deepmerge).default(defaultResult, {
const result = await (0, _options.default)(args);
const expectedOptions = (0, _deepmerge.default)(defaultResult, {
swcOptions: {

@@ -199,4 +219,4 @@ sourceMaps: true

];
const result = await (0, _options).default(args);
const expectedOptions = (0, _deepmerge).default(defaultResult, {
const result = await (0, _options.default)(args);
const expectedOptions = (0, _deepmerge.default)(defaultResult, {
swcOptions: {

@@ -215,6 +235,5 @@ sourceMaps: 'inline'

'src',
'-C',
'-C'
];
expect(()=>(0, _options).default(args)
).toThrow();
expect(()=>(0, _options.default)(args)).toThrow();
});

@@ -229,4 +248,4 @@ it("react development", async ()=>{

];
const result = await (0, _options).default(args);
const expectedOptions = (0, _deepmerge).default(defaultResult.swcOptions, {
const result = await (0, _options.default)(args);
const expectedOptions = (0, _deepmerge.default)(defaultResult.swcOptions, {
jsc: {

@@ -252,4 +271,4 @@ transform: {

];
const result = await (0, _options).default(args);
const expectedOptions = (0, _deepmerge).default(defaultResult.swcOptions, {
const result = await (0, _options.default)(args);
const expectedOptions = (0, _deepmerge.default)(defaultResult.swcOptions, {
jsc: {

@@ -276,4 +295,4 @@ transform: {

];
const result = await (0, _options).default(args);
const expectedOptions = (0, _deepmerge).default(defaultResult.swcOptions, {
const result = await (0, _options.default)(args);
const expectedOptions = (0, _deepmerge.default)(defaultResult.swcOptions, {
jsc: {

@@ -300,4 +319,4 @@ transform: {

];
const result = await (0, _options).default(args);
const expectedOptions = (0, _deepmerge).default(defaultResult.swcOptions, {
const result = await (0, _options.default)(args);
const expectedOptions = (0, _deepmerge.default)(defaultResult.swcOptions, {
no_equals: true

@@ -304,0 +323,0 @@ });

"use strict";
var _sources = require("../sources");
var _fs = _interopRequireDefault(require("fs"));
var _fastGlob = _interopRequireDefault(require("fast-glob"));
Object.defineProperty(exports, "__esModule", {
value: true
});
const _sources = require("../sources");
const _fs = /*#__PURE__*/ _interopRequireDefault(require("fs"));
const _fastGlob = /*#__PURE__*/ _interopRequireDefault(require("fast-glob"));
function _interopRequireDefault(obj) {

@@ -17,3 +20,3 @@ return obj && obj.__esModule ? obj : {

it("exclude dotfiles sources when includeDotfiles=false", async ()=>{
const files = await (0, _sources).globSources([
const files = await (0, _sources.globSources)([
".dotfile"

@@ -31,3 +34,3 @@ ], false);

});
const files = await (0, _sources).globSources([
const files = await (0, _sources.globSources)([
".dotfile"

@@ -52,3 +55,3 @@ ], true);

});
const files = await (0, _sources).globSources([
const files = await (0, _sources.globSources)([
".dotfile",

@@ -73,3 +76,3 @@ "file"

});
const files = await (0, _sources).globSources([
const files = await (0, _sources.globSources)([
".dotfile",

@@ -99,3 +102,3 @@ "file"

]);
const files = await (0, _sources).globSources([
const files = await (0, _sources.globSources)([
"file",

@@ -124,3 +127,3 @@ "directory"

_fastGlob.default.mockRejectedValue(new Error("Failed"));
const files = await (0, _sources).globSources([
const files = await (0, _sources.globSources)([
"file",

@@ -145,3 +148,3 @@ "directory"

];
const [compilable, copyable] = (0, _sources).splitCompilableAndCopyable(files, extensions, true);
const [compilable, copyable] = (0, _sources.splitCompilableAndCopyable)(files, extensions, true);
expect(compilable).toEqual([

@@ -159,3 +162,3 @@ "test.ts"

];
const [compilable, copyable] = (0, _sources).splitCompilableAndCopyable(files, extensions, false);
const [compilable, copyable] = (0, _sources.splitCompilableAndCopyable)(files, extensions, false);
expect(compilable).toEqual([

@@ -162,0 +165,0 @@ "test.ts"

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

});
exports.outputResult = outputResult;
exports.compile = compile;
var _slash = _interopRequireDefault(require("slash"));
var _fs = require("fs");
var _path = require("path");
var _core = require("@swc/core");
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
outputResult: ()=>outputResult,
compile: ()=>compile
});
const _slash = /*#__PURE__*/ _interopRequireDefault(require("slash"));
const _fs = require("fs");
const _path = require("path");
const _core = require("@swc/core");
function _interopRequireDefault(obj) {

@@ -34,3 +42,3 @@ return obj && obj.__esModule ? obj : {

const sourceMapPath = destFile + ".map";
output.code += `\n//# sourceMappingURL=${(0, _slash).default((0, _path).relative(destDir, sourceMapPath))}`;
output.code += `\n//# sourceMappingURL=${(0, _slash.default)((0, _path.relative)(destDir, sourceMapPath))}`;
return {

@@ -43,3 +51,3 @@ sourceMap: output.map,

async function outputResult(output, sourceFile, destFile, options) {
const destDir = (0, _path).dirname(destFile);
const destDir = (0, _path.dirname)(destFile);
const { sourceMap , sourceMapPath , sourceCode } = withSourceMap(output, options, destFile, destDir);

@@ -61,3 +69,3 @@ await mkdir(destDir, {

mode
}),
})
]);

@@ -74,3 +82,3 @@ }

try {
const result = sync ? (0, _core).transformFileSync(filename, options) : await (0, _core).transformFile(filename, options);
const result = sync ? (0, _core.transformFileSync)(filename, options) : await (0, _core.transformFile)(filename, options);
return result;

@@ -77,0 +85,0 @@ } catch (err) {

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

});
exports.CompileStatus = void 0;
Object.defineProperty(exports, "CompileStatus", {
enumerable: true,
get: ()=>CompileStatus
});
var CompileStatus;
exports.CompileStatus = CompileStatus;
(function(CompileStatus) {

@@ -14,4 +16,4 @@ CompileStatus[CompileStatus["Copied"] = 0] = "Copied";

CompileStatus[CompileStatus["Failed"] = 3] = "Failed";
})(CompileStatus || (exports.CompileStatus = CompileStatus = {}));
})(CompileStatus || (CompileStatus = {}));
//# sourceMappingURL=constants.js.map

@@ -5,18 +5,13 @@ "use strict";

});
exports.default = dir;
var _slash = _interopRequireDefault(require("slash"));
var _fs = require("fs");
var _path = require("path");
var _constants = require("./constants");
var _util = require("./util");
var _compile = require("./compile");
var _sources = require("./sources");
async function dir({ cliOptions , swcOptions }) {
const { watch } = cliOptions;
await beforeStartCompilation(cliOptions);
await initialCompilation(cliOptions, swcOptions);
if (watch) {
await watchCompilation(cliOptions, swcOptions);
}
}
Object.defineProperty(exports, "default", {
enumerable: true,
get: ()=>dir
});
const _slash = /*#__PURE__*/ _interopRequireDefault(require("slash"));
const _fs = require("fs");
const _path = require("path");
const _constants = require("./constants");
const _util = require("./util");
const _compile = require("./compile");
const _sources = require("./sources");
function _interopRequireDefault(obj) {

@@ -45,3 +40,3 @@ return obj && obj.__esModule ? obj : {

function getDest(filename, outDir, ext) {
const relativePath = (0, _slash).default((0, _path).relative(cwd, filename));
const relativePath = (0, _slash.default)((0, _path.relative)(cwd, filename));
let base = stripComponents(relativePath);

@@ -51,7 +46,7 @@ if (ext) {

}
return (0, _path).join(outDir, base);
return (0, _path.join)(outDir, base);
}
async function handleCompile(filename, outDir, sync, swcOptions) {
const dest = getDest(filename, outDir, ".js");
const sourceFileName = (0, _slash).default((0, _path).relative((0, _path).dirname(dest), filename));
const sourceFileName = (0, _slash.default)((0, _path.relative)((0, _path.dirname)(dest), filename));
const options = {

@@ -61,5 +56,5 @@ ...swcOptions,

};
const result = await (0, _util).compile(filename, options, sync, dest);
const result = await (0, _util.compile)(filename, options, sync, dest);
if (result) {
await (0, _compile).outputResult(result, filename, dest, options);
await (0, _compile.outputResult)(result, filename, dest, options);
return _constants.CompileStatus.Compiled;

@@ -72,4 +67,4 @@ } else {

const dest = getDest(filename, outDir);
const dir1 = (0, _path).dirname(dest);
await mkdir(dir1, recursive);
const dir = (0, _path.dirname)(dest);
await mkdir(dir, recursive);
await copyFile(filename, dest);

@@ -81,3 +76,3 @@ return _constants.CompileStatus.Copied;

if (deleteDirOnStart) {
const exists = await (0, _fs).existsSync(outDir);
const exists = await (0, _fs.existsSync)(outDir);
if (exists) {

@@ -89,7 +84,7 @@ rm ? await rm(outDir, recursive) : await rmdir(outDir, recursive);

async function initialCompilation(cliOptions, swcOptions) {
const { includeDotfiles , filenames , copyFiles , extensions , outDir , sync , quiet , watch , } = cliOptions;
const { includeDotfiles , filenames , copyFiles , extensions , outDir , sync , quiet , watch } = cliOptions;
const results = new Map();
const start = process.hrtime();
const sourceFiles = await (0, _sources).globSources(filenames, includeDotfiles);
const [compilable, copyable] = (0, _sources).splitCompilableAndCopyable(sourceFiles, extensions, copyFiles);
const sourceFiles = await (0, _sources.globSources)(filenames, includeDotfiles);
const [compilable, copyable] = (0, _sources.splitCompilableAndCopyable)(sourceFiles, extensions, copyFiles);
if (sync) {

@@ -105,9 +100,9 @@ for (const filename of compilable){

}
for (const filename1 of copyable){
for (const filename of copyable){
try {
const result = await handleCopy(filename1, outDir);
results.set(filename1, result);
const result = await handleCopy(filename, outDir);
results.set(filename, result);
} catch (err) {
console.error(err.message);
results.set(filename1, _constants.CompileStatus.Failed);
results.set(filename, _constants.CompileStatus.Failed);
}

@@ -120,6 +115,4 @@ }

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

@@ -146,8 +139,8 @@ compiled.forEach((result, index)=>{

let failed = 0;
let compiled1 = 0;
let copied1 = 0;
for (let [_, status1] of results){
switch(status1){
let compiled = 0;
let copied = 0;
for (let [_, status] of results){
switch(status){
case _constants.CompileStatus.Compiled:
compiled1 += 1;
compiled += 1;
break;

@@ -158,16 +151,16 @@ case _constants.CompileStatus.Failed:

case _constants.CompileStatus.Copied:
copied1 += 1;
copied += 1;
break;
}
}
if (!quiet && compiled1 + copied1) {
if (!quiet && compiled + copied) {
let message = "";
if (compiled1) {
message += `Successfully compiled: ${compiled1} ${compiled1 > 1 ? "files" : "file"}`;
if (compiled) {
message += `Successfully compiled: ${compiled} ${compiled > 1 ? "files" : "file"}`;
}
if (compiled1 && copied1) {
if (compiled && copied) {
message += ", ";
}
if (copied1) {
message += `copied ${copied1} ${copied1 > 1 ? "files" : "file"}`;
if (copied) {
message += `copied ${copied} ${copied > 1 ? "files" : "file"}`;
}

@@ -180,5 +173,3 @@ message += ` with swc (%dms)`;

if (!watch) {
const files = Array.from(results.entries()).filter(([, status])=>status === _constants.CompileStatus.Failed
).map(([filename, _])=>filename
).join("\n");
const files = Array.from(results.entries()).filter(([, status])=>status === _constants.CompileStatus.Failed).map(([filename, _])=>filename).join("\n");
throw new Error(`Failed to compile:\n${files}`);

@@ -189,4 +180,4 @@ }

async function watchCompilation(cliOptions, swcOptions) {
const { includeDotfiles , filenames , copyFiles , extensions , outDir , quiet , sync , } = cliOptions;
const watcher = await (0, _sources).watchSources(filenames, includeDotfiles);
const { includeDotfiles , filenames , copyFiles , extensions , outDir , quiet , sync } = cliOptions;
const watcher = await (0, _sources.watchSources)(filenames, includeDotfiles);
watcher.on("ready", ()=>{

@@ -199,6 +190,6 @@ if (!quiet) {

try {
if ((0, _sources).isCompilableExtension(filename, extensions)) {
if ((0, _sources.isCompilableExtension)(filename, extensions)) {
await unlink(getDest(filename, outDir, ".js"));
const sourcemapPath = getDest(filename, outDir, ".js.map");
const sourcemapExists = await (0, _util).exists(sourcemapPath);
const sourcemapExists = await (0, _util.exists)(sourcemapPath);
if (sourcemapExists) {

@@ -221,3 +212,3 @@ await unlink(sourcemapPath);

watcher.on(type, async (filename)=>{
if ((0, _sources).isCompilableExtension(filename, extensions)) {
if ((0, _sources.isCompilableExtension)(filename, extensions)) {
try {

@@ -249,3 +240,11 @@ const start = process.hrtime();

}
async function dir({ cliOptions , swcOptions }) {
const { watch } = cliOptions;
await beforeStartCompilation(cliOptions);
await initialCompilation(cliOptions, swcOptions);
if (watch) {
await watchCompilation(cliOptions, swcOptions);
}
}
//# sourceMappingURL=dir.js.map

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

});
exports.default = _default;
var _path = _interopRequireDefault(require("path"));
var _slash = _interopRequireDefault(require("slash"));
var _sourceMap = require("source-map");
var _sources = require("./sources");
var util = _interopRequireWildcard(require("./util"));
Object.defineProperty(exports, "default", {
enumerable: true,
get: ()=>_default
});
const _path = /*#__PURE__*/ _interopRequireDefault(require("path"));
const _slash = /*#__PURE__*/ _interopRequireDefault(require("slash"));
const _sourceMap = require("source-map");
const _sources = require("./sources");
const _util = /*#__PURE__*/ _interopRequireWildcard(require("./util"));
function _interopRequireDefault(obj) {

@@ -17,22 +20,40 @@ return obj && obj.__esModule ? obj : {

}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interopRequireWildcard(obj, nodeInterop) {
if (!nodeInterop && 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];
}
}
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
newObj.default = obj;
return newObj;
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}

@@ -91,3 +112,3 @@ async function _default({ cliOptions , swcOptions }) {

if (cliOptions.outFile) {
util.outputFile(result, cliOptions.outFile, swcOptions.sourceMaps);
_util.outputFile(result, cliOptions.outFile, swcOptions.sourceMaps);
} else {

@@ -102,4 +123,4 @@ process.stdout.write(result.code + "\n");

async function handle(filename) {
const sourceFileName = (0, _slash).default(cliOptions.outFile ? _path.default.relative(_path.default.dirname(cliOptions.outFile), filename) : filename);
return await util.compile(filename, {
const sourceFileName = (0, _slash.default)(cliOptions.outFile ? _path.default.relative(_path.default.dirname(cliOptions.outFile), filename) : filename);
return await _util.compile(filename, {
...swcOptions,

@@ -111,4 +132,4 @@ sourceFileName

const results = new Map();
for (const filename of (await (0, _sources).globSources(cliOptions.filenames, cliOptions.includeDotfiles))){
if ((0, _sources).isCompilableExtension(filename, cliOptions.extensions)) {
for (const filename of (await (0, _sources.globSources)(cliOptions.filenames, cliOptions.includeDotfiles))){
if ((0, _sources.isCompilableExtension)(filename, cliOptions.extensions)) {
results.set(filename, previousResults.get(filename));

@@ -121,20 +142,20 @@ }

let results = await getProgram();
for (const filename1 of results.keys()){
for (const filename of results.keys()){
try {
const result = await handle(filename1);
const result = await handle(filename);
if (result) {
results.set(filename1, result);
results.set(filename, result);
} else {
results.delete(filename1);
results.delete(filename);
}
} catch (err) {
console.error(err.message);
results.set(filename1, err);
results.set(filename, err);
}
}
if (cliOptions.watch) {
const watcher = await (0, _sources).watchSources(cliOptions.filenames, cliOptions.includeDotfiles);
const watcher = await (0, _sources.watchSources)(cliOptions.filenames, cliOptions.includeDotfiles);
watcher.on("ready", ()=>{
Promise.resolve().then(async ()=>{
util.assertCompilationResult(results, cliOptions.quiet);
_util.assertCompilationResult(results, cliOptions.quiet);
await output(results.values());

@@ -149,3 +170,3 @@ if (!cliOptions.quiet) {

watcher.on("add", async (filename)=>{
if ((0, _sources).isCompilableExtension(filename, cliOptions.extensions)) {
if ((0, _sources.isCompilableExtension)(filename, cliOptions.extensions)) {
// ensure consistent insertion order when files are added

@@ -163,3 +184,3 @@ results = await getProgram(results);

watcher.on(type, (filename)=>{
if (!(0, _sources).isCompilableExtension(filename, cliOptions.extensions)) {
if (!(0, _sources.isCompilableExtension)(filename, cliOptions.extensions)) {
return;

@@ -174,7 +195,7 @@ }

results.set(filename, result);
util.assertCompilationResult(results, true);
_util.assertCompilationResult(results, true);
await output(results.values());
if (!cliOptions.quiet) {
const [seconds, nanoseconds] = process.hrtime(start);
const ms = seconds * 1000 + nanoseconds * 0.000001;
const ms = seconds * 1000 + nanoseconds * 1e-6;
const name = _path.default.basename(cliOptions.outFile);

@@ -189,3 +210,3 @@ console.log(`Compiled ${name} in ${ms.toFixed(2)}ms`);

} else {
util.assertCompilationResult(results, cliOptions.quiet);
_util.assertCompilationResult(results, cliOptions.quiet);
await output(results.values());

@@ -200,3 +221,3 @@ }

}
const res = await util.transform(cliOptions.filename, code, {
const res = await _util.transform(cliOptions.filename, code, {
...swcOptions,

@@ -203,0 +224,0 @@ sourceFileName: "stdin"

"use strict";
var _dir = _interopRequireDefault(require("./dir"));
var _file = _interopRequireDefault(require("./file"));
var _options = _interopRequireWildcard(require("./options"));
Object.defineProperty(exports, "__esModule", {
value: true
});
const _dir = /*#__PURE__*/ _interopRequireDefault(require("./dir"));
const _file = /*#__PURE__*/ _interopRequireDefault(require("./file"));
const _options = /*#__PURE__*/ _interopRequireWildcard(require("./options"));
function _interopRequireDefault(obj) {

@@ -10,25 +13,43 @@ return obj && obj.__esModule ? obj : {

}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interopRequireWildcard(obj, nodeInterop) {
if (!nodeInterop && 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];
}
}
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
newObj.default = obj;
return newObj;
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}
(0, _options).initProgram();
const opts = (0, _options).default(process.argv);
(0, _options.initProgram)();
const opts = (0, _options.default)(process.argv);
const fn = opts.cliOptions.outDir ? _dir.default : _file.default;

@@ -35,0 +56,0 @@ process.on("uncaughtException", function(err) {

@@ -5,6 +5,74 @@ "use strict";

});
exports.default = parserArgs;
exports.initProgram = void 0;
var _commander = _interopRequireDefault(require("commander"));
var _core = require("@swc/core");
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
initProgram: ()=>initProgram,
default: ()=>parserArgs
});
const _commander = /*#__PURE__*/ _interopRequireDefault(require("commander"));
const _core = require("@swc/core");
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
const pkg = require("../../package.json");
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 ...>");
program.addHelpText("beforeAll", `
============================================================================================
Beta version of @swc/cli is now available via 'swcx' command.
This'll be a default command for @swc/cli@1.
Please give it a try and report any issues at https://github.com/swc-project/swc/issues/4017
============================================================================================
`);
};
function unstringify(val) {
try {
return JSON.parse(val);
} catch {
return val;
}
}
function collect(value, previousValue) {
// If the user passed the option with no value, like "babel file.js --presets", do nothing.
/* istanbul ignore next */ if (typeof value !== "string") return previousValue;
const values = value.split(",");
return previousValue ? previousValue.concat(values) : values;
}
function parserArgs(args) {

@@ -99,64 +167,3 @@ program.parse(args);

}
function _interopRequireDefault(obj) {
return obj && obj.__esModule ? obj : {
default: obj
};
}
const pkg = require("../../package.json");
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 ...>");
program.addHelpText("beforeAll", `
============================================================================================
Beta version of @swc/cli is now available via 'swcx' command.
This'll be a default command for @swc/cli@1.
Please give it a try and report any issues at https://github.com/swc-project/swc/issues/4017
============================================================================================
`);
};
exports.initProgram = initProgram;
function unstringify(val) {
try {
return JSON.parse(val);
} catch {
return val;
}
}
function collect(value, previousValue) {
// If the user passed the option with no value, like "babel file.js --presets", do nothing.
/* istanbul ignore next */ if (typeof value !== "string") return previousValue;
const values = value.split(",");
return previousValue ? previousValue.concat(values) : values;
}
//# sourceMappingURL=options.js.map

@@ -5,11 +5,19 @@ "use strict";

});
exports.globSources = globSources;
exports.isCompilableExtension = isCompilableExtension;
exports.splitCompilableAndCopyable = splitCompilableAndCopyable;
exports.requireChokidar = requireChokidar;
exports.watchSources = watchSources;
var _fastGlob = _interopRequireDefault(require("fast-glob"));
var _slash = _interopRequireDefault(require("slash"));
var _fs = require("fs");
var _path = require("path");
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
globSources: ()=>globSources,
isCompilableExtension: ()=>isCompilableExtension,
splitCompilableAndCopyable: ()=>splitCompilableAndCopyable,
requireChokidar: ()=>requireChokidar,
watchSources: ()=>watchSources
});
const _fastGlob = /*#__PURE__*/ _interopRequireDefault(require("fast-glob"));
const _slash = /*#__PURE__*/ _interopRequireDefault(require("slash"));
const _fs = require("fs");
const _path = require("path");
function _interopRequireDefault(obj) {

@@ -20,22 +28,40 @@ return obj && obj.__esModule ? obj : {

}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interopRequireWildcard(obj, nodeInterop) {
if (!nodeInterop && 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];
}
}
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
newObj.default = obj;
return newObj;
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}

@@ -47,6 +73,5 @@ async function globSources(sources, includeDotfiles = false) {

};
const files = await Promise.all(sources.filter((source)=>includeDotfiles || !(0, _path).basename(source).startsWith(".")
).map((source)=>{
const files = await Promise.all(sources.filter((source)=>includeDotfiles || !(0, _path.basename)(source).startsWith(".")).map((source)=>{
return new Promise((resolve)=>{
(0, _fs).stat(source, (err, stat)=>{
(0, _fs.stat)(source, (err, stat)=>{
if (err) {

@@ -61,5 +86,3 @@ resolve([]);

} else {
(0, _fastGlob).default((0, _slash).default((0, _path).join(source, "**")), globConfig).then((matches)=>resolve(matches)
).catch(()=>resolve([])
);
(0, _fastGlob.default)((0, _slash.default)((0, _path.join)(source, "**")), globConfig).then((matches)=>resolve(matches)).catch(()=>resolve([]));
}

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

function isCompilableExtension(filename, allowedExtension) {
const ext = (0, _path).extname(filename);
const ext = (0, _path.extname)(filename);
return allowedExtension.includes(ext);

@@ -94,5 +117,3 @@ }

try {
const { default: chokidar } = await Promise.resolve().then(function() {
return _interopRequireWildcard(require("chokidar"));
});
const { default: chokidar } = await Promise.resolve().then(()=>/*#__PURE__*/ _interopRequireWildcard(require("chokidar")));
return chokidar;

@@ -107,4 +128,3 @@ } catch (err) {

return chokidar.watch(sources, {
ignored: includeDotfiles ? undefined : (filename)=>(0, _path).basename(filename).startsWith(".")
,
ignored: includeDotfiles ? undefined : (filename)=>(0, _path.basename)(filename).startsWith("."),
ignoreInitial: true,

@@ -111,0 +131,0 @@ awaitWriteFinish: {

@@ -5,11 +5,19 @@ "use strict";

});
exports.exists = exists;
exports.transform = transform;
exports.compile = compile;
exports.outputFile = outputFile;
exports.assertCompilationResult = assertCompilationResult;
var swc = _interopRequireWildcard(require("@swc/core"));
var _slash = _interopRequireDefault(require("slash"));
var _fs = require("fs");
var _path = require("path");
function _export(target, all) {
for(var name in all)Object.defineProperty(target, name, {
enumerable: true,
get: all[name]
});
}
_export(exports, {
exists: ()=>exists,
transform: ()=>transform,
compile: ()=>compile,
outputFile: ()=>outputFile,
assertCompilationResult: ()=>assertCompilationResult
});
const _core = /*#__PURE__*/ _interopRequireWildcard(require("@swc/core"));
const _slash = /*#__PURE__*/ _interopRequireDefault(require("slash"));
const _fs = require("fs");
const _path = require("path");
function _interopRequireDefault(obj) {

@@ -20,22 +28,40 @@ return obj && obj.__esModule ? obj : {

}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interopRequireWildcard(obj, nodeInterop) {
if (!nodeInterop && 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];
}
}
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
newObj.default = obj;
return newObj;
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}

@@ -60,5 +86,5 @@ async function exists(path) {

if (sync) {
return swc.transformSync(code, opts);
return _core.transformSync(code, opts);
}
return swc.transform(code, opts);
return _core.transform(code, opts);
}

@@ -73,3 +99,3 @@ async function compile(filename, opts, sync, outputPath) {

try {
const result = sync ? swc.transformFileSync(filename, opts) : await swc.transformFile(filename, opts);
const result = sync ? _core.transformFileSync(filename, opts) : await _core.transformFile(filename, opts);
if (result.map) {

@@ -95,4 +121,4 @@ // TODO: fix this in core

function outputFile(output, filename, sourceMaps) {
const destDir = (0, _path).dirname(filename);
(0, _fs).mkdirSync(destDir, {
const destDir = (0, _path.dirname)(filename);
(0, _fs.mkdirSync)(destDir, {
recursive: true

@@ -103,8 +129,8 @@ });

// we've requested for a sourcemap to be written to disk
const fileDirName = (0, _path).dirname(filename);
const fileDirName = (0, _path.dirname)(filename);
const mapLoc = filename + ".map";
code += "\n//# sourceMappingURL=" + (0, _slash).default((0, _path).relative(fileDirName, mapLoc));
(0, _fs).writeFileSync(mapLoc, output.map);
code += "\n//# sourceMappingURL=" + (0, _slash.default)((0, _path.relative)(fileDirName, mapLoc));
(0, _fs.writeFileSync)(mapLoc, output.map);
}
(0, _fs).writeFileSync(filename, code);
(0, _fs.writeFileSync)(filename, code);
}

@@ -111,0 +137,0 @@ function assertCompilationResult(result, quiet = false) {

#!/usr/bin/env node
"use strict";
var _minVersion = _interopRequireDefault(require("semver/ranges/min-version"));
var _fs = require("fs");
var path = _interopRequireWildcard(require("path"));
var _childProcess = require("child_process");
Object.defineProperty(exports, "__esModule", {
value: true
});
const _minVersion = /*#__PURE__*/ _interopRequireDefault(require("semver/ranges/min-version"));
const _fs = require("fs");
const _path = /*#__PURE__*/ _interopRequireWildcard(require("path"));
const _childProcess = require("child_process");
function _interopRequireDefault(obj) {

@@ -12,22 +15,40 @@ return obj && obj.__esModule ? obj : {

}
function _interopRequireWildcard(obj) {
if (obj && obj.__esModule) {
function _getRequireWildcardCache(nodeInterop) {
if (typeof WeakMap !== "function") return null;
var cacheBabelInterop = new WeakMap();
var cacheNodeInterop = new WeakMap();
return (_getRequireWildcardCache = function(nodeInterop) {
return nodeInterop ? cacheNodeInterop : cacheBabelInterop;
})(nodeInterop);
}
function _interopRequireWildcard(obj, nodeInterop) {
if (!nodeInterop && 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];
}
}
}
if (obj === null || typeof obj !== "object" && typeof obj !== "function") {
return {
default: obj
};
}
var cache = _getRequireWildcardCache(nodeInterop);
if (cache && cache.has(obj)) {
return cache.get(obj);
}
var newObj = {};
var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
for(var key in obj){
if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
if (desc && (desc.get || desc.set)) {
Object.defineProperty(newObj, key, desc);
} else {
newObj[key] = obj[key];
}
}
newObj.default = obj;
return newObj;
}
newObj.default = obj;
if (cache) {
cache.set(obj, newObj);
}
return newObj;
}

@@ -60,8 +81,8 @@ const { BinWrapper } = require("@mole-inc/bin-wrapper");

if (!process.env[SWC_CLI_ENV.SWCX_SKIP_CORE_VERSION_CHECK]) {
const cwdPackageManifestPath = path.resolve(process.cwd(), "package.json");
if ((0, _fs).existsSync(cwdPackageManifestPath)) {
const { dependencies , devDependencies , } = require(cwdPackageManifestPath);
const cwdPackageManifestPath = _path.resolve(process.cwd(), "package.json");
if ((0, _fs.existsSync)(cwdPackageManifestPath)) {
const { dependencies , devDependencies } = require(cwdPackageManifestPath);
const swcCoreVersion = (dependencies === null || dependencies === void 0 ? void 0 : dependencies["@swc/core"]) || (devDependencies === null || devDependencies === void 0 ? void 0 : devDependencies["@swc/core"]);
if (swcCoreVersion) {
return (0, _minVersion).default(swcCoreVersion);
return (0, _minVersion.default)(swcCoreVersion);
}

@@ -80,6 +101,6 @@ } else {

const isMusl = ()=>(()=>{
function isMusl1() {
function isMusl() {
if (!process.report || typeof process.report.getReport !== "function") {
try {
return (0, _fs).readFileSync("/usr/bin/ldd", "utf8").includes("musl");
return (0, _fs.readFileSync)("/usr/bin/ldd", "utf8").includes("musl");
} catch (e) {

@@ -93,5 +114,4 @@ return true;

}
return isMusl1();
})()
;
return isMusl();
})();
const getBinaryName = ()=>{

@@ -130,3 +150,3 @@ const platformBinaryMap = {

await bin.run();
const binPath = bin.path();
const binPath = bin.path;
const [, , ...args] = process.argv;

@@ -137,7 +157,6 @@ const options = {

};
return (0, _childProcess).spawn(binPath, args, options);
return (0, _childProcess.spawn)(binPath, args, options);
};
executeBinary().catch((e)=>console.error(e)
);
executeBinary().catch((e)=>console.error(e));
//# sourceMappingURL=index.js.map
{
"name": "@swc/cli",
"version": "0.1.61",
"version": "0.1.62",
"description": "CLI for the swc project",

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

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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