Comparing version 0.4.0 to 0.4.1-nightly.20240914
#!/usr/bin/env node | ||
process.title = "swc"; | ||
require("../lib/swc"); | ||
require("../lib/swc/bin.js"); |
@@ -43,5 +43,6 @@ "use strict"; | ||
} | ||
async function initialCompilation(cliOptions, swcOptions) { | ||
async function initialCompilation(cliOptions, swcOptions, callbacks) { | ||
const { includeDotfiles, filenames, copyFiles, extensions, outDir, outFileExtension, stripLeadingPaths, sync, quiet, watch, only, ignore } = cliOptions; | ||
const results = new Map(); | ||
const reasons = new Map(); | ||
const start = process.hrtime(); | ||
@@ -63,3 +64,5 @@ const sourceFiles = await (0, _sources.globSources)(filenames, only, ignore, includeDotfiles); | ||
} catch (err) { | ||
console.error(err.message); | ||
if (!(callbacks === null || callbacks === void 0 ? void 0 : callbacks.onFail)) { | ||
console.error(err.message); | ||
} | ||
results.set(filename, _constants.CompileStatus.Failed); | ||
@@ -73,3 +76,5 @@ } | ||
} catch (err) { | ||
console.error(err.message); | ||
if (!(callbacks === null || callbacks === void 0 ? void 0 : callbacks.onFail)) { | ||
console.error(err.message); | ||
} | ||
results.set(filename, _constants.CompileStatus.Failed); | ||
@@ -93,3 +98,5 @@ } | ||
}).catch((err)=>{ | ||
console.error(err.message); | ||
if (!(callbacks === null || callbacks === void 0 ? void 0 : callbacks.onFail)) { | ||
console.error(err.message); | ||
} | ||
throw err; | ||
@@ -105,2 +112,3 @@ }))), | ||
results.set(filename, _constants.CompileStatus.Failed); | ||
reasons.set(filename, result.reason.message); | ||
} | ||
@@ -135,3 +143,4 @@ }); | ||
} | ||
if (!quiet && compiled + copied) { | ||
const duration = end[1] / 1000000; | ||
if (compiled + copied) { | ||
let message = ""; | ||
@@ -148,17 +157,36 @@ if (compiled) { | ||
message += ` with swc (%dms)`; | ||
console.log(message, (end[1] / 1000000).toFixed(2)); | ||
if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onSuccess) { | ||
if (!failed) { | ||
callbacks.onSuccess({ | ||
duration, | ||
compiled, | ||
copied | ||
}); | ||
} | ||
} else if (!quiet) { | ||
console.log(message, duration.toFixed(2)); | ||
} | ||
} | ||
if (failed) { | ||
console.log(`Failed to compile ${failed} ${failed !== 1 ? "files" : "file"} with swc.`); | ||
if (!watch) { | ||
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}`); | ||
if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onFail) { | ||
callbacks.onFail({ | ||
duration, | ||
reasons | ||
}); | ||
} else { | ||
console.log(`Failed to compile ${failed} ${failed !== 1 ? "files" : "file"} with swc.`); | ||
if (!watch) { | ||
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}`); | ||
} | ||
} | ||
} | ||
} | ||
async function watchCompilation(cliOptions, swcOptions) { | ||
async function watchCompilation(cliOptions, swcOptions, callbacks) { | ||
const { includeDotfiles, filenames, copyFiles, extensions, outDir, stripLeadingPaths, outFileExtension, quiet, sync } = cliOptions; | ||
const watcher = await (0, _sources.watchSources)(filenames, includeDotfiles); | ||
watcher.on("ready", ()=>{ | ||
if (!quiet) { | ||
if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onWatchReady) { | ||
callbacks.onWatchReady(); | ||
} else if (!quiet) { | ||
console.info("Watching for file changes."); | ||
@@ -191,4 +219,9 @@ } | ||
if ((0, _sources.isCompilableExtension)(filename, extensions)) { | ||
const start = process.hrtime(); | ||
const getDuration = ()=>{ | ||
const end = process.hrtime(start); | ||
const duration = end[1] / 1000000; | ||
return duration; | ||
}; | ||
try { | ||
const start = process.hrtime(); | ||
const result = await (0, _dirWorker.default)({ | ||
@@ -202,20 +235,59 @@ filename, | ||
}); | ||
if (!quiet && result === _constants.CompileStatus.Compiled) { | ||
const end = process.hrtime(start); | ||
console.log(`Successfully compiled ${filename} with swc (%dms)`, (end[1] / 1000000).toFixed(2)); | ||
const duration = getDuration(); | ||
if (result === _constants.CompileStatus.Compiled) { | ||
if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onSuccess) { | ||
callbacks.onSuccess({ | ||
duration, | ||
compiled: 1, | ||
filename | ||
}); | ||
} else if (!quiet) { | ||
console.log(`Successfully compiled ${filename} with swc (%dms)`, duration.toFixed(2)); | ||
} | ||
} | ||
} catch (err) { | ||
console.error(err.message); | ||
} catch (error) { | ||
if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onFail) { | ||
const reasons = new Map(); | ||
reasons.set(filename, error.message); | ||
callbacks.onFail({ | ||
duration: getDuration(), | ||
reasons | ||
}); | ||
} else { | ||
console.error(error.message); | ||
} | ||
} | ||
} else if (copyFiles) { | ||
const start = process.hrtime(); | ||
const getDuration = ()=>{ | ||
const end = process.hrtime(start); | ||
const duration = end[1] / 1000000; | ||
return duration; | ||
}; | ||
try { | ||
const start = process.hrtime(); | ||
const result = await handleCopy(filename, outDir, stripLeadingPaths); | ||
if (!quiet && result === _constants.CompileStatus.Copied) { | ||
const end = process.hrtime(start); | ||
console.log(`Successfully copied ${filename} with swc (%dms)`, (end[1] / 1000000).toFixed(2)); | ||
if (result === _constants.CompileStatus.Copied) { | ||
const duration = getDuration(); | ||
if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onSuccess) { | ||
callbacks.onSuccess({ | ||
duration, | ||
copied: 1, | ||
filename | ||
}); | ||
} else if (!quiet) { | ||
console.log(`Successfully copied ${filename} with swc (%dms)`, duration.toFixed(2)); | ||
} | ||
} | ||
} catch (err) { | ||
console.error(`Failed to copy ${filename}`); | ||
console.error(err.message); | ||
} catch (error) { | ||
if (callbacks === null || callbacks === void 0 ? void 0 : callbacks.onFail) { | ||
const reasons = new Map(); | ||
reasons.set(filename, error.message); | ||
callbacks.onFail({ | ||
duration: getDuration(), | ||
reasons | ||
}); | ||
} else { | ||
console.error(`Failed to copy ${filename}`); | ||
console.error(error.message); | ||
} | ||
} | ||
@@ -226,8 +298,8 @@ } | ||
} | ||
async function dir({ cliOptions, swcOptions }) { | ||
async function dir({ cliOptions, swcOptions, callbacks }) { | ||
const { watch } = cliOptions; | ||
await beforeStartCompilation(cliOptions); | ||
await initialCompilation(cliOptions, swcOptions); | ||
await initialCompilation(cliOptions, swcOptions, callbacks); | ||
if (watch) { | ||
await watchCompilation(cliOptions, swcOptions); | ||
await watchCompilation(cliOptions, swcOptions, callbacks); | ||
} | ||
@@ -234,0 +306,0 @@ } |
@@ -5,5 +5,9 @@ "use strict"; | ||
}); | ||
Object.defineProperty(exports, "swcDir", { | ||
enumerable: true, | ||
get: function() { | ||
return _dir.default; | ||
} | ||
}); | ||
const _dir = /*#__PURE__*/ _interop_require_default(require("./dir")); | ||
const _file = /*#__PURE__*/ _interop_require_default(require("./file")); | ||
const _options = /*#__PURE__*/ _interop_require_wildcard(require("./options")); | ||
function _interop_require_default(obj) { | ||
@@ -14,55 +18,3 @@ return obj && obj.__esModule ? obj : { | ||
} | ||
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 _interop_require_wildcard(obj, nodeInterop) { | ||
if (!nodeInterop && obj && obj.__esModule) { | ||
return obj; | ||
} | ||
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 = { | ||
__proto__: null | ||
}; | ||
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; | ||
if (cache) { | ||
cache.set(obj, newObj); | ||
} | ||
return newObj; | ||
} | ||
(0, _options.initProgram)(); | ||
const opts = (0, _options.default)(process.argv); | ||
const fn = opts.cliOptions.outDir ? _dir.default : _file.default; | ||
process.on("uncaughtException", function(err) { | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
fn(opts).catch((err)=>{ | ||
console.error(err); | ||
process.exit(1); | ||
}); | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@swc/cli", | ||
"version": "0.4.0", | ||
"version": "0.4.1-nightly.20240914", | ||
"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
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
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
179878
31
1819