From 48cffc9b55feef7837da0cd5396e089e3e0a82c1 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Wed, 27 Jul 2022 09:21:34 -0700 Subject: [PATCH 1/7] feat(loaders): replace tsloader into swc --- scripts/build.js | 16 ++--- src/index.js | 119 +++++++++++++++++++------------------- src/loaders/swc-loader.js | 110 +++++++++++++++++++++++++++++++++++ src/loaders/ts-loader.js | 24 -------- src/typescript.js | 15 ----- 5 files changed, 179 insertions(+), 105 deletions(-) create mode 100644 src/loaders/swc-loader.js delete mode 100644 src/loaders/ts-loader.js delete mode 100644 src/typescript.js diff --git a/scripts/build.js b/scripts/build.js index 8da0caec..48063765 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -53,17 +53,17 @@ async function main() { ); checkUnknownAssets('shebang-loader', Object.keys(shebangLoaderAssets)); - const { code: tsLoader, assets: tsLoaderAssets } = await ncc( - __dirname + "/../src/loaders/ts-loader", + const { code: swcLoader, assets: swcLoaderAssets } = await ncc( + __dirname + "/../src/loaders/swc-loader", { - filename: "ts-loader.js", + filename: "swc-loader.js", minify, cache, v8cache, noAssetBuilds: true }, ); - checkUnknownAssets('ts-loader', Object.keys(tsLoaderAssets).filter(asset => !asset.startsWith('lib/') && !asset.startsWith('typescript/lib'))); + checkUnknownAssets('swc-loader', Object.keys(swcLoaderAssets).filter(asset => asset !== 'wasm_bg.wasm')); const { code: stringifyLoader, assets: stringifyLoaderAssets } = await ncc( __dirname + "/../src/loaders/stringify-loader", @@ -92,7 +92,8 @@ async function main() { writeFileSync(__dirname + "/../dist/ncc/sourcemap-register.js.cache", sourcemapAssets["sourcemap-register.js.cache"].source); writeFileSync(__dirname + "/../dist/ncc/loaders/relocate-loader.js.cache", relocateLoaderAssets["relocate-loader.js.cache"].source); writeFileSync(__dirname + "/../dist/ncc/loaders/shebang-loader.js.cache", shebangLoaderAssets["shebang-loader.js.cache"].source); - writeFileSync(__dirname + "/../dist/ncc/loaders/ts-loader.js.cache", tsLoaderAssets["ts-loader.js.cache"].source); + writeFileSync(__dirname + "/../dist/ncc/loaders/swc-loader.js.cache", swcLoaderAssets["swc-loader.js.cache"].source); + writeFileSync(__dirname + "/../dist/ncc/loaders/wasm_bg.wasm", swcLoaderAssets["wasm_bg.wasm"].source); writeFileSync(__dirname + "/../dist/ncc/loaders/stringify-loader.js.cache", stringifyLoaderAssets["stringify-loader.js.cache"].source); writeFileSync(__dirname + "/../dist/ncc/cli.js.cache.js", cliAssets["cli.js.cache.js"].source); @@ -100,16 +101,15 @@ async function main() { writeFileSync(__dirname + "/../dist/ncc/sourcemap-register.js.cache.js", sourcemapAssets["sourcemap-register.js.cache.js"].source); writeFileSync(__dirname + "/../dist/ncc/loaders/relocate-loader.js.cache.js", relocateLoaderAssets["relocate-loader.js.cache.js"].source); writeFileSync(__dirname + "/../dist/ncc/loaders/shebang-loader.js.cache.js", shebangLoaderAssets["shebang-loader.js.cache.js"].source); - writeFileSync(__dirname + "/../dist/ncc/loaders/ts-loader.js.cache.js", tsLoaderAssets["ts-loader.js.cache.js"].source); + writeFileSync(__dirname + "/../dist/ncc/loaders/swc-loader.js.cache.js", swcLoaderAssets["swc-loader.js.cache.js"].source); writeFileSync(__dirname + "/../dist/ncc/loaders/stringify-loader.js.cache.js", stringifyLoaderAssets["stringify-loader.js.cache.js"].source); writeFileSync(__dirname + "/../dist/ncc/cli.js", cli, { mode: 0o777 }); writeFileSync(__dirname + "/../dist/ncc/index.js", index); - writeFileSync(__dirname + "/../dist/ncc/typescript.js", readFileSync(__dirname + "/../src/typescript.js")); writeFileSync(__dirname + "/../dist/ncc/sourcemap-register.js", sourcemapSupport); writeFileSync(__dirname + "/../dist/ncc/loaders/relocate-loader.js", relocateLoader); writeFileSync(__dirname + "/../dist/ncc/loaders/shebang-loader.js", shebangLoader); - writeFileSync(__dirname + "/../dist/ncc/loaders/ts-loader.js", tsLoader); + writeFileSync(__dirname + "/../dist/ncc/loaders/swc-loader.js", swcLoader); writeFileSync(__dirname + "/../dist/ncc/loaders/stringify-loader.js", stringifyLoader); writeFileSync(__dirname + "/../dist/ncc/loaders/uncacheable.js", readFileSync(__dirname + "/../src/loaders/uncacheable.js")); writeFileSync(__dirname + "/../dist/ncc/loaders/empty-loader.js", readFileSync(__dirname + "/../src/loaders/empty-loader.js")); diff --git a/src/index.js b/src/index.js index 593ea088..3698fd93 100644 --- a/src/index.js +++ b/src/index.js @@ -5,12 +5,10 @@ const { join, dirname, extname, relative, resolve: pathResolve } = require("path const webpack = require("webpack"); const MemoryFS = require("memory-fs"); const terser = require("terser"); -const tsconfigPaths = require("tsconfig-paths"); -const { loadTsconfig } = require("tsconfig-paths/lib/tsconfig-loader"); -const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin"); const shebangRegEx = require('./utils/shebang'); const nccCacheDir = require("./utils/ncc-cache-dir"); -const LicenseWebpackPlugin = require('license-webpack-plugin').LicenseWebpackPlugin; +const JSON5 = require("json5"); +const { LicenseWebpackPlugin } = require('license-webpack-plugin'); const { version: nccVersion } = require('../package.json'); const { hasTypeModule } = require('./utils/has-type-module'); @@ -21,10 +19,10 @@ const SUPPORTED_EXTENSIONS = [".js", ".json", ".node", ".mjs", ".ts", ".tsx"]; const hashOf = name => { return crypto - .createHash("sha256") - .update(name) - .digest("hex") - .slice(0, 10); + .createHash("sha256") + .update(name) + .digest("hex") + .slice(0, 10); } const defaultPermissions = 0o666; @@ -32,7 +30,7 @@ const defaultPermissions = 0o666; const relocateLoader = eval('require(__dirname + "/loaders/relocate-loader.js")'); module.exports = ncc; -function ncc ( +function ncc( entry, { cache, @@ -57,7 +55,7 @@ function ncc ( production = true, // webpack defaults to `module` and `main`, but that's // not really what node.js supports, so we reset it - mainFields = ['main'] + mainFields = ['main'], } = {} ) { // v8 cache not supported for ES modules @@ -76,7 +74,7 @@ function ncc ( extensions: SUPPORTED_EXTENSIONS, exportsFields: ["exports"], importsFields: ["imports"], - conditionNames: ["import", "node", production ? "production": "development"] + conditionNames: ["import", "node", production ? "production" : "development"] }); const ext = extname(filename); @@ -108,32 +106,24 @@ function ncc ( existingAssetNames.push(`${filename}.cache`); existingAssetNames.push(`${filename}.cache${ext}`); } + + let tsconfig = {}; const resolvePlugins = []; - // add TsconfigPathsPlugin to support `paths` resolution in tsconfig - // we need to catch here because the plugin will - // error if there's no tsconfig in the working directory - let fullTsconfig = {}; + const resolveModules = []; + const compilerOptions = tsconfig.compilerOptions || {}; try { - const configFileAbsolutePath = walkParentDirs({ + const configPath = walkParentDirs({ base: process.cwd(), start: dirname(entry), filename: 'tsconfig.json', }); - fullTsconfig = loadTsconfig(configFileAbsolutePath) || { - compilerOptions: {} - }; + const contents = fs.readFileSync(configPath, 'utf8') + tsconfig = JSON5.parse(contents); + const baseUrl = tsconfig.compilerOptions.baseUrl; + resolveModules.push(pathResolve(dirname(configPath), baseUrl)); + } catch (e) { } - const tsconfigPathsOptions = { silent: true } - if (fullTsconfig.compilerOptions.allowJs) { - tsconfigPathsOptions.extensions = SUPPORTED_EXTENSIONS - } - resolvePlugins.push(new TsconfigPathsPlugin(tsconfigPathsOptions)); - const tsconfig = tsconfigPaths.loadConfig(); - if (tsconfig.resultType === "success") { - tsconfigMatchPath = tsconfigPaths.createMatchPath(tsconfig.absoluteBaseUrl, tsconfig.paths); - } - } catch (e) {} resolvePlugins.push({ apply(resolver) { @@ -227,7 +217,7 @@ function ncc ( if (tapInfo.name !== "CommonJsPlugin") { return tapInfo; } - tapInfo.fn = () => {}; + tapInfo.fn = () => { }; return tapInfo; } }); @@ -245,8 +235,7 @@ function ncc ( } ] - if (typeof license === 'string' && license.length > 0) - { + if (typeof license === 'string' && license.length > 0) { plugins.push(new LicenseWebpackPlugin({ outputFilename: license })); @@ -315,11 +304,12 @@ function ncc ( undefined: cjsDeps() }, mainFields, - plugins: resolvePlugins + plugins: resolvePlugins, + modules: resolveModules.length > 0 ? resolveModules : undefined, }, // https://github.com/vercel/ncc/pull/29#pullrequestreview-177152175 node: false, - externals ({ context, request, dependencyType }, callback) { + externals({ context, request, dependencyType }, callback) { const external = externalMap.get(request); if (external) return callback(null, `${dependencyType === 'esm' && esm ? 'module' : 'node-commonjs'} ${external}`); return callback(); @@ -354,17 +344,30 @@ function ncc ( loader: eval('__dirname + "/loaders/uncacheable.js"') }, { - loader: eval('__dirname + "/loaders/ts-loader.js"'), + loader: eval('__dirname + "/loaders/swc-loader.js"'), options: { - transpileOnly, - compiler: eval('__dirname + "/typescript.js"'), - compilerOptions: { - module: 'esnext', - target: 'esnext', - ...fullTsconfig.compilerOptions, - allowSyntheticDefaultImports: true, - noEmit: false, - outDir: '//' + minify: false, // TODO: maybe we could omit terser if `true`? + exclude: tsconfig.exclude, + sourceMaps: compilerOptions.sourceMap || false, + module: { + type: compilerOptions.module && compilerOptions.module.toLowerCase() === 'commonjs' ? 'commonjs' : 'es6', + strict: false, + strictMode: true, + lazy: false, + noInterop: !compilerOptions.esModuleInterop + }, + jsc: { + externalHelpers: false, + keepClassNames: true, + target: compilerOptions.target && compilerOptions.target.toLowerCase() || 'es2021', + paths: compilerOptions.paths, + baseUrl: compilerOptions.baseUrl, + parser: { + syntax: 'typescript', + tsx: true, // TODO: use tsconfig.compilerOptions.jsx ??? + decorators: compilerOptions.experimentalDecorators || false, + dynamicImport: true, // TODO: use module ??? + } } } }] @@ -395,10 +398,10 @@ function ncc ( }); }); }) - .then(finalizeHandler, function (err) { - compilationStack.pop(); - throw err; - }); + .then(finalizeHandler, function (err) { + compilationStack.pop(); + throw err; + }); } else { if (typeof watch === 'object') { @@ -425,7 +428,7 @@ function ncc ( }); let closed = false; return { - close () { + close() { if (!watcher) throw new Error('No watcher to close.'); if (closed) @@ -433,7 +436,7 @@ function ncc ( closed = true; watcher.close(); }, - handler (handler) { + handler(handler) { if (watchHandler) throw new Error('Watcher handler already provided.'); watchHandler = handler; @@ -442,7 +445,7 @@ function ncc ( cachedResult = null; } }, - rebuild (handler) { + rebuild(handler) { if (rebuildHandler) throw new Error('Rebuild handler already provided.'); rebuildHandler = handler; @@ -450,9 +453,9 @@ function ncc ( }; } - async function finalizeHandler (stats) { + async function finalizeHandler(stats) { const assets = Object.create(null); - getFlatFiles(mfs.data, assets, relocateLoader.getAssetMeta, fullTsconfig); + getFlatFiles(mfs.data, assets, relocateLoader.getAssetMeta, compilerOptions); // filter symlinks to existing assets const symlinks = Object.create(null); for (const [key, value] of Object.entries(relocateLoader.getSymlinks())) { @@ -593,7 +596,7 @@ function ncc ( const subbuildAssets = []; for (const asset of Object.keys(assets)) { if (!asset.endsWith('.js') && !asset.endsWith('.cjs') && !asset.endsWith('.ts') && !asset.endsWith('.mjs') || - asset.endsWith('.cache.js') || asset.endsWith('.cache.cjs') || asset.endsWith('.cache.ts') || asset.endsWith('.cache.mjs') || asset.endsWith('.d.ts')) { + asset.endsWith('.cache.js') || asset.endsWith('.cache.cjs') || asset.endsWith('.cache.ts') || asset.endsWith('.cache.mjs') || asset.endsWith('.d.ts')) { existingAssetNames.push(asset); continue; } @@ -646,17 +649,17 @@ function ncc ( } // this could be rewritten with actual FS apis / globs, but this is simpler -function getFlatFiles(mfsData, output, getAssetMeta, tsconfig, curBase = "") { +function getFlatFiles(mfsData, output, getAssetMeta, compilerOptions, curBase = "") { for (const path of Object.keys(mfsData)) { const item = mfsData[path]; let curPath = `${curBase}/${path}`; // directory - if (item[""] === true) getFlatFiles(item, output, getAssetMeta, tsconfig, curPath); + if (item[""] === true) getFlatFiles(item, output, getAssetMeta, compilerOptions, curPath); // file else if (!curPath.endsWith("/")) { const meta = getAssetMeta(curPath.slice(1)) || {}; - if(curPath.endsWith(".d.ts")) { - const outDir = tsconfig.compilerOptions.outDir ? pathResolve(tsconfig.compilerOptions.outDir) : pathResolve('dist'); + if (curPath.endsWith(".d.ts")) { + const outDir = compilerOptions?.compilerOptions?.outDir ? pathResolve(compilerOptions.compilerOptions.outDir) : pathResolve('dist'); curPath = curPath .replace(outDir, "") .replace(process.cwd(), "") diff --git a/src/loaders/swc-loader.js b/src/loaders/swc-loader.js new file mode 100644 index 00000000..e1784987 --- /dev/null +++ b/src/loaders/swc-loader.js @@ -0,0 +1,110 @@ +// Source code from https://github.com/swc-project/swc-loader/blob/master/src/index.js +// with the following changes: +// - swapped out `@swc/core` for `@swc/wasm` +// - swapped out `swc.transform()` for `swc.transformSync()` + +const swc = require("@swc/wasm"); + +function makeLoader() { + return function (source, inputSourceMap) { + // Make the loader async + const callback = this.async(); + const filename = this.resourcePath; + + let loaderOptions = this.getOptions() || {}; + + // Standardize on 'sourceMaps' as the key passed through to Webpack, so that + // users may safely use either one alongside our default use of + // 'this.sourceMap' below without getting error about conflicting aliases. + if ( + Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMap") && + !Object.prototype.hasOwnProperty.call(loaderOptions, "sourceMaps") + ) { + loaderOptions = Object.assign({}, loaderOptions, { + sourceMaps: loaderOptions.sourceMap, + }); + delete loaderOptions.sourceMap; + } + + if (inputSourceMap) { + inputSourceMap = JSON.stringify(inputSourceMap); + } + + const programmaticOptions = Object.assign({}, loaderOptions, { + filename, + inputSourceMap: inputSourceMap || undefined, + + // Set the default sourcemap behavior based on Webpack's mapping flag, + // but allow users to override if they want. + sourceMaps: + loaderOptions.sourceMaps === undefined + ? this.sourceMap + : loaderOptions.sourceMaps, + + // Ensure that Webpack will get a full absolute path in the sourcemap + // so that it can properly map the module back to its internal cached + // modules. + sourceFileName: filename, + }); + if (!programmaticOptions.inputSourceMap) { + delete programmaticOptions.inputSourceMap; + } + + const sync = programmaticOptions.sync; + const parseMap = programmaticOptions.parseMap; + + // Remove loader related options + delete programmaticOptions.sync; + delete programmaticOptions.parseMap; + delete programmaticOptions.customize; + delete programmaticOptions.cacheDirectory; + delete programmaticOptions.cacheIdentifier; + delete programmaticOptions.cacheCompression; + delete programmaticOptions.metadataSubscribers; + + // auto detect development mode + if (this.mode && programmaticOptions.jsc && programmaticOptions.jsc.transform + && programmaticOptions.jsc.transform.react && + !Object.prototype.hasOwnProperty.call(programmaticOptions.jsc.transform.react, "development")) { + programmaticOptions.jsc.transform.react.development = this.mode === 'development' + } + + if (programmaticOptions.sourceMaps === "inline") { + // Babel has this weird behavior where if you set "inline", we + // inline the sourcemap, and set 'result.map = null'. This results + // in bad behavior from Babel since the maps get put into the code, + // which Webpack does not expect, and because the map we return to + // Webpack is null, which is also bad. To avoid that, we override the + // behavior here so "inline" just behaves like 'true'. + programmaticOptions.sourceMaps = true; + } + + try { + if (sync) { + const output = swc.transformSync(source, programmaticOptions); + callback( + null, + output.code, + parseMap ? JSON.parse(output.map) : output.map + ); + } else { + try { + const output = swc.transformSync(source, programmaticOptions); + callback( + null, + output.code, + parseMap ? JSON.parse(output.map) : output.map + ); + } catch (err) { + callback(err); + + } + } + } catch (e) { + callback(e); + } + }; +} + +module.exports = makeLoader(); +module.exports.custom = makeLoader; \ No newline at end of file diff --git a/src/loaders/ts-loader.js b/src/loaders/ts-loader.js deleted file mode 100644 index 71f65480..00000000 --- a/src/loaders/ts-loader.js +++ /dev/null @@ -1,24 +0,0 @@ -// we re-export so that we generate a unique -// optional bundle for the ts-loader, that -// doesn't get loaded unless the user is -// compiling typescript -const logger = require("ts-loader/dist/logger"); -const makeLogger = logger.makeLogger; -logger.makeLogger = function (loaderOptions, colors) { - const instance = makeLogger(loaderOptions, colors); - const logWarning = instance.logWarning; - instance.logWarning = function (message) { - // Disable TS Loader TypeScript compatibility warning - if (message.indexOf('This version may or may not be compatible with ts-loader') !== -1) - return; - return logWarning(message); - }; - return instance; -}; - -module.exports = require("ts-loader"); - -// ts-loader internally has a require("typescript") that applies -// regardless of "compiler". -// We could remap this too, as soon as ncc supports aliased externals -module.exports.typescript = require("typescript"); diff --git a/src/typescript.js b/src/typescript.js deleted file mode 100644 index 9140cc59..00000000 --- a/src/typescript.js +++ /dev/null @@ -1,15 +0,0 @@ - -const { Module } = require('module'); -const m = new Module('', null); -const { quiet, typescriptLookupPath } = JSON.parse(process.env.__NCC_OPTS || '{}'); -m.paths = Module._nodeModulePaths(process.env.TYPESCRIPT_LOOKUP_PATH || typescriptLookupPath || (process.cwd() + '/')); -let typescript; -try { - typescript = m.require('typescript'); - if (!quiet) console.log("ncc: Using typescript@" + typescript.version + " (local user-provided)"); -} -catch (e) { - typescript = require('typescript'); - if (!quiet) console.log("ncc: Using typescript@" + typescript.version + " (ncc built-in)"); -} -module.exports = typescript; From c7d97b152ed85a5cdfd3567f1f8468def2b5551c Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Wed, 11 May 2022 11:33:19 -0700 Subject: [PATCH 2/7] test(unit): update test fixtures --- test/unit/bundle-subasset2/output.js | 4 +- test/unit/ts-exts/output.js | 83 +++++-------------- test/unit/ts-mixed-modules/output.js | 48 +++++++++-- test/unit/ts-target-es2018/output.js | 4 +- test/unit/tsconfig-paths-allowjs/output.js | 48 ++++++++++- .../output.js | 48 ++++++++++- test/unit/tsconfig-paths/output.js | 48 ++++++++++- 7 files changed, 197 insertions(+), 86 deletions(-) diff --git a/test/unit/bundle-subasset2/output.js b/test/unit/bundle-subasset2/output.js index 2350d9b3..73feab11 100644 --- a/test/unit/bundle-subasset2/output.js +++ b/test/unit/bundle-subasset2/output.js @@ -91,9 +91,9 @@ const external_path_namespaceObject = require("path"); const piscina = new (external_piscina_default())({ - filename: __nccwpck_require__.ab + "pi-bridge.js", + filename: __nccwpck_require__.ab + "pi-bridge.js" }); -(async function () { +(async function() { const result = await piscina.runTask(2); console.log(result); })(); diff --git a/test/unit/ts-exts/output.js b/test/unit/ts-exts/output.js index a6bf1111..df9717a3 100644 --- a/test/unit/ts-exts/output.js +++ b/test/unit/ts-exts/output.js @@ -1,77 +1,38 @@ /******/ (() => { // webpackBootstrap /******/ "use strict"; -/******/ var __webpack_modules__ = ({ - -/***/ 668: -/***/ ((__unused_webpack_module, exports) => { - - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports["default"] = {}; - - -/***/ }), - -/***/ 975: -/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { - - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports["default"] = void 0; -var dep_dep_js_1 = __nccwpck_require__(668); -Object.defineProperty(exports, "default", ({ enumerable: true, get: function () { return dep_dep_js_1.default; } })); - - -/***/ }) - -/******/ }); -/************************************************************************/ -/******/ // The module cache -/******/ var __webpack_module_cache__ = {}; +/******/ // The require scope +/******/ var __nccwpck_require__ = {}; /******/ -/******/ // The require function -/******/ function __nccwpck_require__(moduleId) { -/******/ // Check if module is in cache -/******/ var cachedModule = __webpack_module_cache__[moduleId]; -/******/ if (cachedModule !== undefined) { -/******/ return cachedModule.exports; -/******/ } -/******/ // Create a new module (and put it into the cache) -/******/ var module = __webpack_module_cache__[moduleId] = { -/******/ // no module.id needed -/******/ // no module.loaded needed -/******/ exports: {} +/************************************************************************/ +/******/ /* webpack/runtime/make namespace object */ +/******/ (() => { +/******/ // define __esModule on exports +/******/ __nccwpck_require__.r = (exports) => { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); /******/ }; +/******/ })(); /******/ -/******/ // Execute the module function -/******/ var threw = true; -/******/ try { -/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); -/******/ threw = false; -/******/ } finally { -/******/ if(threw) delete __webpack_module_cache__[moduleId]; -/******/ } -/******/ -/******/ // Return the exports of the module -/******/ return module.exports; -/******/ } -/******/ -/************************************************************************/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; /******/ /************************************************************************/ var __webpack_exports__ = {}; -// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. -(() => { -var exports = __webpack_exports__; +// ESM COMPAT FLAG +__nccwpck_require__.r(__webpack_exports__); + +;// CONCATENATED MODULE: ./test/unit/ts-exts/dep-dep.ts +/* harmony default export */ const dep_dep = ({}); + +;// CONCATENATED MODULE: ./test/unit/ts-exts/dep.ts + -Object.defineProperty(exports, "__esModule", ({ value: true })); -const dep_js_1 = __nccwpck_require__(975); -console.log(dep_js_1.default); +;// CONCATENATED MODULE: ./test/unit/ts-exts/input.ts -})(); +console.log(dep_dep); module.exports = __webpack_exports__; /******/ })() diff --git a/test/unit/ts-mixed-modules/output.js b/test/unit/ts-mixed-modules/output.js index 7f0260f3..d22412d6 100644 --- a/test/unit/ts-mixed-modules/output.js +++ b/test/unit/ts-mixed-modules/output.js @@ -2,17 +2,20 @@ /******/ "use strict"; /******/ var __webpack_modules__ = ({ -/***/ 119: -/***/ ((module, exports) => { +/***/ 559: +/***/ ((module, __webpack_exports__, __nccwpck_require__) => { - -Object.defineProperty(exports, "__esModule", ({ value: true })); +__nccwpck_require__.r(__webpack_exports__); +/* module decorator */ module = __nccwpck_require__.hmd(module); const config = { - routes: ['/foo'] + routes: [ + '/foo' + ] }; module.exports = config; + /***/ }) /******/ }); @@ -29,8 +32,8 @@ module.exports = config; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { -/******/ // no module.id needed -/******/ // no module.loaded needed +/******/ id: moduleId, +/******/ loaded: false, /******/ exports: {} /******/ }; /******/ @@ -43,11 +46,40 @@ module.exports = config; /******/ if(threw) delete __webpack_module_cache__[moduleId]; /******/ } /******/ +/******/ // Flag the module as loaded +/******/ module.loaded = true; +/******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ +/******/ /* webpack/runtime/harmony module decorator */ +/******/ (() => { +/******/ __nccwpck_require__.hmd = (module) => { +/******/ module = Object.create(module); +/******/ if (!module.children) module.children = []; +/******/ Object.defineProperty(module, 'exports', { +/******/ enumerable: true, +/******/ set: () => { +/******/ throw new Error('ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: ' + module.id); +/******/ } +/******/ }); +/******/ return module; +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ (() => { +/******/ // define __esModule on exports +/******/ __nccwpck_require__.r = (exports) => { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ })(); +/******/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; @@ -57,7 +89,7 @@ module.exports = config; /******/ // startup /******/ // Load entry module and return exports /******/ // This entry module is referenced by other modules so it can't be inlined -/******/ var __webpack_exports__ = __nccwpck_require__(119); +/******/ var __webpack_exports__ = __nccwpck_require__(559); /******/ module.exports = __webpack_exports__; /******/ /******/ })() diff --git a/test/unit/ts-target-es2018/output.js b/test/unit/ts-target-es2018/output.js index 5f2aaf14..e39a893a 100644 --- a/test/unit/ts-target-es2018/output.js +++ b/test/unit/ts-target-es2018/output.js @@ -1,13 +1,11 @@ /******/ (() => { // webpackBootstrap -/******/ "use strict"; /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; /******/ /************************************************************************/ var __webpack_exports__ = {}; - -if (process === null || process === void 0 ? void 0 : process.env.FOO) { +if (process?.env.FOO) { console.log('foo'); } diff --git a/test/unit/tsconfig-paths-allowjs/output.js b/test/unit/tsconfig-paths-allowjs/output.js index f7da7944..bc41a94c 100644 --- a/test/unit/tsconfig-paths-allowjs/output.js +++ b/test/unit/tsconfig-paths-allowjs/output.js @@ -42,6 +42,46 @@ module.exports = eval("require")("@module"); /******/ } /******/ /************************************************************************/ +/******/ /* webpack/runtime/compat get default export */ +/******/ (() => { +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __nccwpck_require__.n = (module) => { +/******/ var getter = module && module.__esModule ? +/******/ () => (module['default']) : +/******/ () => (module); +/******/ __nccwpck_require__.d(getter, { a: getter }); +/******/ return getter; +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/define property getters */ +/******/ (() => { +/******/ // define getter functions for harmony exports +/******/ __nccwpck_require__.d = (exports, definition) => { +/******/ for(var key in definition) { +/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); +/******/ } +/******/ } +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/hasOwnProperty shorthand */ +/******/ (() => { +/******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) +/******/ })(); +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ (() => { +/******/ // define __esModule on exports +/******/ __nccwpck_require__.r = (exports) => { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ })(); +/******/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; @@ -51,11 +91,11 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be in strict mode. (() => { "use strict"; -var exports = __webpack_exports__; +__nccwpck_require__.r(__webpack_exports__); +/* harmony import */ var _module__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(17); +/* harmony import */ var _module__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(_module__WEBPACK_IMPORTED_MODULE_0__); -Object.defineProperty(exports, "__esModule", ({ value: true })); -const _module_1 = __nccwpck_require__(17); -console.log(_module_1.default); +console.log((_module__WEBPACK_IMPORTED_MODULE_0___default())); })(); diff --git a/test/unit/tsconfig-paths-conflicting-external/output.js b/test/unit/tsconfig-paths-conflicting-external/output.js index f7da7944..bc41a94c 100644 --- a/test/unit/tsconfig-paths-conflicting-external/output.js +++ b/test/unit/tsconfig-paths-conflicting-external/output.js @@ -42,6 +42,46 @@ module.exports = eval("require")("@module"); /******/ } /******/ /************************************************************************/ +/******/ /* webpack/runtime/compat get default export */ +/******/ (() => { +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __nccwpck_require__.n = (module) => { +/******/ var getter = module && module.__esModule ? +/******/ () => (module['default']) : +/******/ () => (module); +/******/ __nccwpck_require__.d(getter, { a: getter }); +/******/ return getter; +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/define property getters */ +/******/ (() => { +/******/ // define getter functions for harmony exports +/******/ __nccwpck_require__.d = (exports, definition) => { +/******/ for(var key in definition) { +/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); +/******/ } +/******/ } +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/hasOwnProperty shorthand */ +/******/ (() => { +/******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) +/******/ })(); +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ (() => { +/******/ // define __esModule on exports +/******/ __nccwpck_require__.r = (exports) => { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ })(); +/******/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; @@ -51,11 +91,11 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be in strict mode. (() => { "use strict"; -var exports = __webpack_exports__; +__nccwpck_require__.r(__webpack_exports__); +/* harmony import */ var _module__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(17); +/* harmony import */ var _module__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(_module__WEBPACK_IMPORTED_MODULE_0__); -Object.defineProperty(exports, "__esModule", ({ value: true })); -const _module_1 = __nccwpck_require__(17); -console.log(_module_1.default); +console.log((_module__WEBPACK_IMPORTED_MODULE_0___default())); })(); diff --git a/test/unit/tsconfig-paths/output.js b/test/unit/tsconfig-paths/output.js index f7da7944..bc41a94c 100644 --- a/test/unit/tsconfig-paths/output.js +++ b/test/unit/tsconfig-paths/output.js @@ -42,6 +42,46 @@ module.exports = eval("require")("@module"); /******/ } /******/ /************************************************************************/ +/******/ /* webpack/runtime/compat get default export */ +/******/ (() => { +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __nccwpck_require__.n = (module) => { +/******/ var getter = module && module.__esModule ? +/******/ () => (module['default']) : +/******/ () => (module); +/******/ __nccwpck_require__.d(getter, { a: getter }); +/******/ return getter; +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/define property getters */ +/******/ (() => { +/******/ // define getter functions for harmony exports +/******/ __nccwpck_require__.d = (exports, definition) => { +/******/ for(var key in definition) { +/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { +/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); +/******/ } +/******/ } +/******/ }; +/******/ })(); +/******/ +/******/ /* webpack/runtime/hasOwnProperty shorthand */ +/******/ (() => { +/******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) +/******/ })(); +/******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ (() => { +/******/ // define __esModule on exports +/******/ __nccwpck_require__.r = (exports) => { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ })(); +/******/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; @@ -51,11 +91,11 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be in strict mode. (() => { "use strict"; -var exports = __webpack_exports__; +__nccwpck_require__.r(__webpack_exports__); +/* harmony import */ var _module__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(17); +/* harmony import */ var _module__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(_module__WEBPACK_IMPORTED_MODULE_0__); -Object.defineProperty(exports, "__esModule", ({ value: true })); -const _module_1 = __nccwpck_require__(17); -console.log(_module_1.default); +console.log((_module__WEBPACK_IMPORTED_MODULE_0___default())); })(); From 8536da27886543fa331f404704c274e9e25757f8 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Wed, 11 May 2022 15:13:31 -0700 Subject: [PATCH 3/7] test(fixtures): remove redundant ts error tests --- test/fixtures/ts-error2/ts-error.ts | 5 ----- test/fixtures/ts-error2/tsconfig.json | 5 ----- test/fixtures/with-type-errors/ts-error.ts | 5 ----- test/fixtures/with-type-errors/tsconfig.json | 5 ----- 4 files changed, 20 deletions(-) delete mode 100644 test/fixtures/ts-error2/ts-error.ts delete mode 100644 test/fixtures/ts-error2/tsconfig.json delete mode 100644 test/fixtures/with-type-errors/ts-error.ts delete mode 100644 test/fixtures/with-type-errors/tsconfig.json diff --git a/test/fixtures/ts-error2/ts-error.ts b/test/fixtures/ts-error2/ts-error.ts deleted file mode 100644 index 9400f1c9..00000000 --- a/test/fixtures/ts-error2/ts-error.ts +++ /dev/null @@ -1,5 +0,0 @@ -require.extensions['.asdf'] = function () {}; - -function p (x: Y) { - -} \ No newline at end of file diff --git a/test/fixtures/ts-error2/tsconfig.json b/test/fixtures/ts-error2/tsconfig.json deleted file mode 100644 index 798a4ed7..00000000 --- a/test/fixtures/ts-error2/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "compilerOptions": { - "target": "es2015" - } -} diff --git a/test/fixtures/with-type-errors/ts-error.ts b/test/fixtures/with-type-errors/ts-error.ts deleted file mode 100644 index 9400f1c9..00000000 --- a/test/fixtures/with-type-errors/ts-error.ts +++ /dev/null @@ -1,5 +0,0 @@ -require.extensions['.asdf'] = function () {}; - -function p (x: Y) { - -} \ No newline at end of file diff --git a/test/fixtures/with-type-errors/tsconfig.json b/test/fixtures/with-type-errors/tsconfig.json deleted file mode 100644 index 798a4ed7..00000000 --- a/test/fixtures/with-type-errors/tsconfig.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "compilerOptions": { - "target": "es2015" - } -} From 92f43d11bee7bb40c6c9ba2bda4e0c4e7aa9e33d Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Wed, 11 May 2022 16:39:59 -0700 Subject: [PATCH 4/7] test(cli): update cli tests --- test/cli.js | 19 ------------------- test/cli.test.js | 17 +++++++++-------- 2 files changed, 9 insertions(+), 27 deletions(-) diff --git a/test/cli.js b/test/cli.js index 8df03fda..b66282a2 100644 --- a/test/cli.js +++ b/test/cli.js @@ -60,16 +60,6 @@ module.exports = [ return code === 1 && stderr.toString().indexOf('fail.ts:2:1') !== -1; } }, - { - args: ["run", "test/fixtures/ts-error2/ts-error.ts"], - expect (code, stdout, stderr) { - return code === 1 && stderr.toString().indexOf('ts-error.ts(3,16)') !== -1 && stderr.toString().split('\n').length < 11; - } - }, - { - args: ["run", "-t", "test/fixtures/with-type-errors/ts-error.ts"], - expect: { code: 0 } - }, { args: ["build", "-o", "tmp", "test/fixtures/test.cjs"], expect (code, stdout, stderr) { @@ -101,15 +91,6 @@ module.exports = [ return stdout.length === 0; } }, - { - args: ["build", "test/integration/test.ts"], - env: { - TYPESCRIPT_LOOKUP_PATH: '/tmp/nowhere' - }, - expect (code, stdout) { - return code === 0 && stdout.indexOf('ncc built-in') !== -1; - }, - }, { args: ["build", "-o", "tmp", "test/fixtures/module.cjs"], expect (code, stdout) { diff --git a/test/cli.test.js b/test/cli.test.js index b8c3e0cc..c98ddb2b 100644 --- a/test/cli.test.js +++ b/test/cli.test.js @@ -5,22 +5,23 @@ const file = global.coverage ? "/../src/cli.js" : "/../dist/ncc/cli.js"; jest.setTimeout(20000); -for (const cliTest of cliTests) { - it(`should execute "ncc ${(cliTest.args || []).join(" ")}"`, async () => { - const ps = fork(join(__dirname, file), cliTest.args || [], { +describe('cli', () => { + it.each(cliTests)('should execute ncc $args', async ({ args, env, expect: e, timeout }) => { + + const ps = fork(join(__dirname, file), args || [], { stdio: "pipe", - env: { ...process.env, ...cliTest.env }, + env: { ...process.env, ...env }, }); let stderr = "", stdout = ""; ps.stderr.on("data", chunk => stderr += chunk.toString()); ps.stdout.on("data", chunk => stdout += chunk.toString()); - const expected = cliTest.expect || { code: 0 }; + const expected = e ?? { code: 0 }; let timedOut = false; - if (cliTest.timeout) + if (timeout) setTimeout(() => { timedOut = true; ps.kill(); - }, cliTest.timeout); + }, timeout); const code = await new Promise(resolve => ps.on("close", resolve)); if (typeof expected === "function") expect(expected(code, stdout, stderr, timedOut)).toBe(true); @@ -31,4 +32,4 @@ for (const cliTest of cliTests) { expect(timedOut).toBe(true); } }); -} +}); From 0b14cec2aefbe08b1a8350138131ed73f5dd2ace Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Wed, 10 Aug 2022 09:27:31 -0700 Subject: [PATCH 5/7] build(package): bump up dependencies --- package.json | 8 +++---- yarn.lock | 64 ++++++++++++++++------------------------------------ 2 files changed, 23 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index 4df6d435..f9b17656 100644 --- a/package.json +++ b/package.json @@ -27,6 +27,7 @@ "@google-cloud/firestore": "^4.14.0", "@sentry/node": "^6.10.0", "@slack/web-api": "^6.3.0", + "@swc/wasm": "^1.2.224", "@tensorflow/tfjs-node": "^3.12.0", "@vercel/webpack-asset-relocator-loader": "1.7.2", "analytics-node": "^6.0.0", @@ -62,6 +63,7 @@ "isomorphic-unfetch": "^3.0.0", "jest": "^27.5.1", "jimp": "^0.16.1", + "json5": "^2.2.1", "jugglingdb": "2.0.1", "koa": "^2.6.2", "leveldown": "^6.0.0", @@ -96,15 +98,13 @@ "socket.io": "^4.1.3", "source-map-support": "^0.5.9", "stripe": "^8.167.0", + "swc-loader": "^0.2.3", "swig": "^1.4.2", "terser": "^5.6.1", "the-answer": "^1.0.0", "tiny-json-http": "^7.0.2", - "ts-loader": "^9.3.0", - "tsconfig-paths": "^3.7.0", - "tsconfig-paths-webpack-plugin": "^3.2.0", "twilio": "^3.23.2", - "typescript": "^4.4.2", + "typescript": "^4.7.4", "vm2": "^3.6.6", "vue": "^2.5.17", "vue-server-renderer": "^2.5.17", diff --git a/yarn.lock b/yarn.lock index e8811808..71a5bbd9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2083,6 +2083,11 @@ p-queue "^6.6.1" p-retry "^4.0.0" +"@swc/wasm@^1.2.224": + version "1.2.224" + resolved "https://registry.yarnpkg.com/@swc/wasm/-/wasm-1.2.224.tgz#8642026023839963867d4da71ba35d899b3647f8" + integrity sha512-AZ+mtWWWg3DP8FSi7IC2WHnhODvZaPA/jGOy1ztNm/hHls9JxsqoE7zkLtDdZo47cFbhFlyEFqyoDiOTWuZsWA== + "@szmarczak/http-timer@^1.1.2": version "1.1.2" resolved "https://registry.yarnpkg.com/@szmarczak/http-timer/-/http-timer-1.1.2.tgz#b1665e2c461a2cd92f4c1bbf50d5454de0d4b421" @@ -2438,11 +2443,6 @@ resolved "https://registry.yarnpkg.com/@types/json-schema/-/json-schema-7.0.9.tgz#97edc9037ea0c38585320b28964dde3b39e4660d" integrity sha512-qcUXuemtEu+E5wZSJHNxUXeCZhAfXKQ41D+duX+VYPde7xyEVZci+/oXKJL13tnRs9lR2pr4fod59GT6/X1/yQ== -"@types/json5@^0.0.29": - version "0.0.29" - resolved "https://registry.yarnpkg.com/@types/json5/-/json5-0.0.29.tgz#ee28707ae94e11d2b827bcbe5270bcea7f3e71ee" - integrity sha1-7ihweulOEdK4J7y+UnC86n8+ce4= - "@types/keygrip@*": version "1.0.2" resolved "https://registry.yarnpkg.com/@types/keygrip/-/keygrip-1.0.2.tgz#513abfd256d7ad0bf1ee1873606317b33b1b2a72" @@ -5796,7 +5796,7 @@ engine.io@~5.1.1: engine.io-parser "~4.0.0" ws "~7.4.2" -enhanced-resolve@^5.0.0, enhanced-resolve@^5.7.0, enhanced-resolve@^5.8.3: +enhanced-resolve@^5.8.3: version "5.9.3" resolved "https://registry.yarnpkg.com/enhanced-resolve/-/enhanced-resolve-5.9.3.tgz#44a342c012cbc473254af5cc6ae20ebd0aae5d88" integrity sha512-Bq9VSor+kjvW3f9/MiiR4eE3XYgOl7/rS8lnSxbRbF3kS0B2r+Y9w5krBWxZgDxASVZbdYrn5wT4j/Wb0J9qow== @@ -9199,13 +9199,6 @@ json-stringify-safe@^5.0.1, json-stringify-safe@~5.0.1: resolved "https://registry.yarnpkg.com/json-stringify-safe/-/json-stringify-safe-5.0.1.tgz#1296a2d58fd45f19a0f6ce01d65701e2c735b6eb" integrity sha1-Epai1Y/UXxmg9s4B1lcB4sc1tus= -json5@^1.0.1: - version "1.0.1" - resolved "https://registry.yarnpkg.com/json5/-/json5-1.0.1.tgz#779fb0018604fa854eacbf6252180d83543e3dbe" - integrity sha512-aKS4WQjPenRxiQsC93MNfjx+nbF4PAdYzmd/1JIj8HYzqfbu86beTuNgXDzPknWk0n0uARlyewZo4s++ES36Ow== - dependencies: - minimist "^1.2.0" - json5@^2.1.2: version "2.2.0" resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.0.tgz#2dfefe720c6ba525d9ebd909950f0515316c89a3" @@ -9213,6 +9206,11 @@ json5@^2.1.2: dependencies: minimist "^1.2.5" +json5@^2.2.1: + version "2.2.1" + resolved "https://registry.yarnpkg.com/json5/-/json5-2.2.1.tgz#655d50ed1e6f95ad1a3caababd2b0efda10b395c" + integrity sha512-1hqLFMSrGHRHxav9q9gNjJ5EXznIxGVO09xQRrwplcS8qs28pZ8s8hupZAmqDwZUmVZ2Qb2jnyPOWcDH8m8dlA== + jsonfile@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/jsonfile/-/jsonfile-4.0.0.tgz#8771aae0799b64076b76640fca058f9c10e33ecb" @@ -10406,7 +10404,7 @@ micromatch@^3.1.10, micromatch@^3.1.4: snapdragon "^0.8.1" to-regex "^3.0.2" -micromatch@^4.0.0, micromatch@^4.0.4: +micromatch@^4.0.4: version "4.0.4" resolved "https://registry.yarnpkg.com/micromatch/-/micromatch-4.0.4.tgz#896d519dfe9db25fce94ceb7a500919bf881ebf9" integrity sha512-pRmzw/XUcwXGpD9aI9q/0XOwLNygjETJ8y0ao0wdqprrzDa4YnxLcz7fQRZr8voh8V10kGhABbNcHVk5wHgWwg== @@ -10522,7 +10520,7 @@ minimist@0.0.8: resolved "https://registry.yarnpkg.com/minimist/-/minimist-0.0.8.tgz#857fcabfc3397d2625b8228262e86aa7a011b05d" integrity sha1-hX/Kv8M5fSYluCKCYuhqp6ARsF0= -minimist@^1.1.0, minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5, minimist@^1.2.6: +minimist@^1.1.0, minimist@^1.1.1, minimist@^1.1.3, minimist@^1.2.0, minimist@^1.2.3, minimist@^1.2.5: version "1.2.6" resolved "https://registry.yarnpkg.com/minimist/-/minimist-1.2.6.tgz#8637a5b759ea0d6e98702cfb3a9283323c93af44" integrity sha512-Jsjnk4bw3YJqYzbdyBiNsPWHPfO++UGG749Cxs6peCu5Xg4nrena6OVxOYxrQTqww0Jmwt+Ref8rggumkTLz9Q== @@ -14638,6 +14636,11 @@ swap-case@^1.1.0: lower-case "^1.1.1" upper-case "^1.1.1" +swc-loader@^0.2.3: + version "0.2.3" + resolved "https://registry.yarnpkg.com/swc-loader/-/swc-loader-0.2.3.tgz#6792f1c2e4c9ae9bf9b933b3e010210e270c186d" + integrity sha512-D1p6XXURfSPleZZA/Lipb3A8pZ17fP4NObZvFCDjK/OKljroqDpPmsBdTraWhVBqUNpcWBQY1imWdoPScRlQ7A== + swig@^1.4.2: version "1.4.2" resolved "https://registry.yarnpkg.com/swig/-/swig-1.4.2.tgz#4085ca0453369104b5d483e2841b39b7ae1aaba5" @@ -15058,35 +15061,6 @@ ts-invariant@^0.4.0: dependencies: tslib "^1.9.3" -ts-loader@^9.3.0: - version "9.3.0" - resolved "https://registry.yarnpkg.com/ts-loader/-/ts-loader-9.3.0.tgz#980f4dbfb60e517179e15e10ed98e454b132159f" - integrity sha512-2kLLAdAD+FCKijvGKi9sS0OzoqxLCF3CxHpok7rVgCZ5UldRzH0TkbwG9XECKjBzHsAewntC5oDaI/FwKzEUog== - dependencies: - chalk "^4.1.0" - enhanced-resolve "^5.0.0" - micromatch "^4.0.0" - semver "^7.3.4" - -tsconfig-paths-webpack-plugin@^3.2.0: - version "3.5.1" - resolved "https://registry.yarnpkg.com/tsconfig-paths-webpack-plugin/-/tsconfig-paths-webpack-plugin-3.5.1.tgz#e4dbf492a20dca9caab60086ddacb703afc2b726" - integrity sha512-n5CMlUUj+N5pjBhBACLq4jdr9cPTitySCjIosoQm0zwK99gmrcTGAfY9CwxRFT9+9OleNWXPRUcxsKP4AYExxQ== - dependencies: - chalk "^4.1.0" - enhanced-resolve "^5.7.0" - tsconfig-paths "^3.9.0" - -tsconfig-paths@^3.7.0, tsconfig-paths@^3.9.0: - version "3.14.1" - resolved "https://registry.yarnpkg.com/tsconfig-paths/-/tsconfig-paths-3.14.1.tgz#ba0734599e8ea36c862798e920bcf163277b137a" - integrity sha512-fxDhWnFSLt3VuTwtvJt5fpwxBHg5AdKWMsgcPOOIilyjymcYVZoCQF8fvFRezCNfblEXmi+PcM1eYHeOAgXCOQ== - dependencies: - "@types/json5" "^0.0.29" - json5 "^1.0.1" - minimist "^1.2.6" - strip-bom "^3.0.0" - tslib@1.10.0: version "1.10.0" resolved "https://registry.yarnpkg.com/tslib/-/tslib-1.10.0.tgz#c3c19f95973fb0a62973fb09d90d961ee43e5c8a" @@ -15198,7 +15172,7 @@ typedarray@^0.0.6: resolved "https://registry.yarnpkg.com/typedarray/-/typedarray-0.0.6.tgz#867ac74e3864187b1d3d47d996a78ec5c8830777" integrity sha1-hnrHTjhkGHsdPUfZlqeOxciDB3c= -typescript@^4.4.2: +typescript@^4.7.4: version "4.7.4" resolved "https://registry.yarnpkg.com/typescript/-/typescript-4.7.4.tgz#1a88596d1cf47d59507a1bcdfb5b9dfe4d488235" integrity sha512-C0WQT0gezHuw6AdY1M2jxUO83Rjf0HP7Sk1DtXj6j1EwkQNZrHAg2XPWlq62oqEhYvONq5pkC2Y9oPljWToLmQ== From c46c5ca9690320f8d89b92e631f6627d31de9e32 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Wed, 10 Aug 2022 09:50:10 -0700 Subject: [PATCH 6/7] fix(ncc): correct few compiler options --- src/index.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/index.js b/src/index.js index 3698fd93..3acb5d9f 100644 --- a/src/index.js +++ b/src/index.js @@ -110,7 +110,6 @@ function ncc( let tsconfig = {}; const resolvePlugins = []; const resolveModules = []; - const compilerOptions = tsconfig.compilerOptions || {}; try { const configPath = walkParentDirs({ base: process.cwd(), @@ -123,20 +122,20 @@ function ncc( resolveModules.push(pathResolve(dirname(configPath), baseUrl)); } catch (e) { } - + const compilerOptions = tsconfig.compilerOptions || {}; resolvePlugins.push({ apply(resolver) { const resolve = resolver.resolve; - resolver.resolve = function (context, path, request, resolveContext, callback) { + resolver.resolve = function(context, path, request, resolveContext, callback) { const self = this; - resolve.call(self, context, path, request, resolveContext, function (err, innerPath, result) { + resolve.call(self, context, path, request, resolveContext, function(err, innerPath, result) { if (result) return callback(null, innerPath, result); if (err && !err.message.startsWith('Can\'t resolve')) return callback(err); // Allow .js resolutions to .tsx? from .tsx? if (request.endsWith('.js') && context.issuer && (context.issuer.endsWith('.ts') || context.issuer.endsWith('.tsx'))) { - return resolve.call(self, context, path, request.slice(0, -3), resolveContext, function (err, innerPath, result) { + return resolve.call(self, context, path, request.slice(0, -3), resolveContext, function(err, innerPath, result) { if (result) return callback(null, innerPath, result); if (err && !err.message.startsWith('Can\'t resolve')) return callback(err); @@ -346,7 +345,7 @@ function ncc( { loader: eval('__dirname + "/loaders/swc-loader.js"'), options: { - minify: false, // TODO: maybe we could omit terser if `true`? + minify: false, exclude: tsconfig.exclude, sourceMaps: compilerOptions.sourceMap || false, module: { @@ -398,7 +397,7 @@ function ncc( }); }); }) - .then(finalizeHandler, function (err) { + .then(finalizeHandler, function(err) { compilationStack.pop(); throw err; }); @@ -659,7 +658,7 @@ function getFlatFiles(mfsData, output, getAssetMeta, compilerOptions, curBase = else if (!curPath.endsWith("/")) { const meta = getAssetMeta(curPath.slice(1)) || {}; if (curPath.endsWith(".d.ts")) { - const outDir = compilerOptions?.compilerOptions?.outDir ? pathResolve(compilerOptions.compilerOptions.outDir) : pathResolve('dist'); + const outDir = compilerOptions?.outDir ? pathResolve(compilerOptions.outDir) : pathResolve('dist'); curPath = curPath .replace(outDir, "") .replace(process.cwd(), "") From 93ea7273d0355adb328497db021727cf5f61a8c5 Mon Sep 17 00:00:00 2001 From: OJ Kwon Date: Wed, 10 Aug 2022 11:18:32 -0700 Subject: [PATCH 7/7] test(ncc): update fixtures --- test/unit/bundle-subasset/output-coverage.js | 4 +- test/unit/bundle-subasset2/output-coverage.js | 4 +- test/unit/custom-emit/output-coverage.js | 4 +- .../double-nested-builds/output-coverage.js | 4 +- test/unit/exports-nomodule/output-coverage.js | 1 - test/unit/exports-wildcard/output-coverage.js | 1 - test/unit/externals/output-coverage.js | 19 +++-- test/unit/imports/output-coverage.js | 1 - test/unit/minify-err/output-coverage.js | 4 +- test/unit/nested-builds/output-coverage.js | 4 +- test/unit/ts-exts/output-coverage.js | 26 +++--- test/unit/ts-exts/output.js | 85 ++++++++++++++----- test/unit/ts-mixed-modules/output-coverage.js | 12 ++- test/unit/ts-mixed-modules/output.js | 42 ++------- test/unit/ts-target-es2018/output.js | 4 +- .../tsconfig-paths-allowjs/output-coverage.js | 48 ++--------- test/unit/tsconfig-paths-allowjs/output.js | 50 +---------- .../output-coverage.js | 18 ++-- .../output.js | 50 +---------- test/unit/tsconfig-paths/output-coverage.js | 18 ++-- test/unit/tsconfig-paths/output.js | 50 +---------- 21 files changed, 154 insertions(+), 295 deletions(-) diff --git a/test/unit/bundle-subasset/output-coverage.js b/test/unit/bundle-subasset/output-coverage.js index 8ba72bcc..db50e5fc 100644 --- a/test/unit/bundle-subasset/output-coverage.js +++ b/test/unit/bundle-subasset/output-coverage.js @@ -2,7 +2,7 @@ /******/ "use strict"; /******/ var __webpack_modules__ = ({ -/***/ 622: +/***/ 17: /***/ ((module) => { module.exports = require("path"); @@ -91,7 +91,7 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. (() => { __nccwpck_require__.r(__webpack_exports__); -/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(622); +/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(17); /* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(path__WEBPACK_IMPORTED_MODULE_0__); diff --git a/test/unit/bundle-subasset2/output-coverage.js b/test/unit/bundle-subasset2/output-coverage.js index 2350d9b3..73feab11 100644 --- a/test/unit/bundle-subasset2/output-coverage.js +++ b/test/unit/bundle-subasset2/output-coverage.js @@ -91,9 +91,9 @@ const external_path_namespaceObject = require("path"); const piscina = new (external_piscina_default())({ - filename: __nccwpck_require__.ab + "pi-bridge.js", + filename: __nccwpck_require__.ab + "pi-bridge.js" }); -(async function () { +(async function() { const result = await piscina.runTask(2); console.log(result); })(); diff --git a/test/unit/custom-emit/output-coverage.js b/test/unit/custom-emit/output-coverage.js index e860540f..7af3db9b 100644 --- a/test/unit/custom-emit/output-coverage.js +++ b/test/unit/custom-emit/output-coverage.js @@ -1,7 +1,7 @@ /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ -/***/ 747: +/***/ 147: /***/ ((module) => { "use strict"; @@ -50,7 +50,7 @@ module.exports = require("fs"); var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. (() => { -const { readFileSync } = __nccwpck_require__(747); +const { readFileSync } = __nccwpck_require__(147); console.log(readFileSync(__dirname + './test.json')); diff --git a/test/unit/double-nested-builds/output-coverage.js b/test/unit/double-nested-builds/output-coverage.js index fcae3669..063ffb2d 100644 --- a/test/unit/double-nested-builds/output-coverage.js +++ b/test/unit/double-nested-builds/output-coverage.js @@ -128,7 +128,7 @@ /***/ ((module) => { "use strict"; -module.exports = __nccwpck_require__(622); +module.exports = __nccwpck_require__(17); /***/ }) @@ -182,7 +182,7 @@ module.exports = __nccwpck_require__(622); /***/ }), -/***/ 622: +/***/ 17: /***/ ((module) => { "use strict"; diff --git a/test/unit/exports-nomodule/output-coverage.js b/test/unit/exports-nomodule/output-coverage.js index 376d6075..63d25ba8 100644 --- a/test/unit/exports-nomodule/output-coverage.js +++ b/test/unit/exports-nomodule/output-coverage.js @@ -1,4 +1,3 @@ -/******/ "use strict"; /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; diff --git a/test/unit/exports-wildcard/output-coverage.js b/test/unit/exports-wildcard/output-coverage.js index 2d0fa3ae..36cc6b47 100644 --- a/test/unit/exports-wildcard/output-coverage.js +++ b/test/unit/exports-wildcard/output-coverage.js @@ -1,4 +1,3 @@ -/******/ "use strict"; /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; diff --git a/test/unit/externals/output-coverage.js b/test/unit/externals/output-coverage.js index 37ad607a..11bf2373 100644 --- a/test/unit/externals/output-coverage.js +++ b/test/unit/externals/output-coverage.js @@ -1,7 +1,15 @@ /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ -/***/ 306: +/***/ 378: +/***/ ((module) => { + +"use strict"; +module.exports = require("external-replace/replaced/some-file"); + +/***/ }), + +/***/ 830: /***/ ((module) => { "use strict"; @@ -9,7 +17,7 @@ module.exports = require("externalmapped"); /***/ }), -/***/ 196: +/***/ 958: /***/ ((module) => { "use strict"; @@ -58,12 +66,13 @@ module.exports = require("regexexternal"); var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. (() => { -const external = __nccwpck_require__(306); -const regexpExternal = __nccwpck_require__(196); +const external = __nccwpck_require__(830); +const regexpExternal = __nccwpck_require__(958); +const regexpExternalMatch = __nccwpck_require__(378) console.log(external); console.log(regexpExternal); - +console.log(regexpExternalMatch); })(); diff --git a/test/unit/imports/output-coverage.js b/test/unit/imports/output-coverage.js index 1c32d92c..c9cf2863 100644 --- a/test/unit/imports/output-coverage.js +++ b/test/unit/imports/output-coverage.js @@ -1,4 +1,3 @@ -/******/ "use strict"; /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = new URL('.', import.meta.url).pathname.slice(import.meta.url.match(/^file:\/\/\/\w:/) ? 1 : 0, -1) + "/"; diff --git a/test/unit/minify-err/output-coverage.js b/test/unit/minify-err/output-coverage.js index 7479315a..0ea68bff 100644 --- a/test/unit/minify-err/output-coverage.js +++ b/test/unit/minify-err/output-coverage.js @@ -16,7 +16,7 @@ module.exports = webpackEmptyContext; /***/ }), -/***/ 747: +/***/ 147: /***/ ((module) => { "use strict"; @@ -71,7 +71,7 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. (() => { if (global.GENTLY) __nccwpck_require__(875) = GENTLY.hijack(eval("require")); -console.log(__nccwpck_require__(747)); +console.log(__nccwpck_require__(147)); })(); diff --git a/test/unit/nested-builds/output-coverage.js b/test/unit/nested-builds/output-coverage.js index d3b675a9..09faa87d 100644 --- a/test/unit/nested-builds/output-coverage.js +++ b/test/unit/nested-builds/output-coverage.js @@ -11,7 +11,7 @@ /***/ 622: /***/ ((module) => { - module.exports = __nccwpck_require__(622); + module.exports = __nccwpck_require__(17); /***/ }) @@ -118,7 +118,7 @@ /***/ }), -/***/ 622: +/***/ 17: /***/ ((module) => { "use strict"; diff --git a/test/unit/ts-exts/output-coverage.js b/test/unit/ts-exts/output-coverage.js index 6a6e64e7..afec49dc 100644 --- a/test/unit/ts-exts/output-coverage.js +++ b/test/unit/ts-exts/output-coverage.js @@ -2,24 +2,28 @@ /******/ "use strict"; /******/ var __webpack_modules__ = ({ -/***/ 119: +/***/ 124: /***/ ((__unused_webpack_module, exports) => { -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.default = {}; +Object.defineProperty(exports, "default", ({ + enumerable: true, + get: ()=>_default +})); +const _default = {}; /***/ }), -/***/ 43: +/***/ 841: /***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.default = void 0; -var dep_dep_js_1 = __nccwpck_require__(119); -Object.defineProperty(exports, "default", ({ enumerable: true, get: function () { return dep_dep_js_1.default; } })); +Object.defineProperty(exports, "default", ({ + enumerable: true, + get: ()=>_depDepJs.default +})); +const _depDepJs = __nccwpck_require__(124); /***/ }) @@ -65,11 +69,9 @@ Object.defineProperty(exports, "default", ({ enumerable: true, get: function () var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. (() => { -var exports = __webpack_exports__; -Object.defineProperty(exports, "__esModule", ({ value: true })); -const dep_js_1 = __nccwpck_require__(43); -console.log(dep_js_1.default); +const _depJs = __nccwpck_require__(841); +console.log(_depJs.default); })(); diff --git a/test/unit/ts-exts/output.js b/test/unit/ts-exts/output.js index df9717a3..17bf6975 100644 --- a/test/unit/ts-exts/output.js +++ b/test/unit/ts-exts/output.js @@ -1,38 +1,79 @@ /******/ (() => { // webpackBootstrap /******/ "use strict"; -/******/ // The require scope -/******/ var __nccwpck_require__ = {}; -/******/ +/******/ var __webpack_modules__ = ({ + +/***/ 165: +/***/ ((__unused_webpack_module, exports) => { + + +Object.defineProperty(exports, "default", ({ + enumerable: true, + get: ()=>_default +})); +const _default = {}; + + +/***/ }), + +/***/ 344: +/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { + + +Object.defineProperty(exports, "default", ({ + enumerable: true, + get: ()=>_depDepJs.default +})); +const _depDepJs = __nccwpck_require__(165); + + +/***/ }) + +/******/ }); /************************************************************************/ -/******/ /* webpack/runtime/make namespace object */ -/******/ (() => { -/******/ // define __esModule on exports -/******/ __nccwpck_require__.r = (exports) => { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ // The module cache +/******/ var __webpack_module_cache__ = {}; +/******/ +/******/ // The require function +/******/ function __nccwpck_require__(moduleId) { +/******/ // Check if module is in cache +/******/ var cachedModule = __webpack_module_cache__[moduleId]; +/******/ if (cachedModule !== undefined) { +/******/ return cachedModule.exports; +/******/ } +/******/ // Create a new module (and put it into the cache) +/******/ var module = __webpack_module_cache__[moduleId] = { +/******/ // no module.id needed +/******/ // no module.loaded needed +/******/ exports: {} /******/ }; -/******/ })(); /******/ +/******/ // Execute the module function +/******/ var threw = true; +/******/ try { +/******/ __webpack_modules__[moduleId](module, module.exports, __nccwpck_require__); +/******/ threw = false; +/******/ } finally { +/******/ if(threw) delete __webpack_module_cache__[moduleId]; +/******/ } +/******/ +/******/ // Return the exports of the module +/******/ return module.exports; +/******/ } +/******/ +/************************************************************************/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; /******/ /************************************************************************/ var __webpack_exports__ = {}; -// ESM COMPAT FLAG -__nccwpck_require__.r(__webpack_exports__); - -;// CONCATENATED MODULE: ./test/unit/ts-exts/dep-dep.ts -/* harmony default export */ const dep_dep = ({}); - -;// CONCATENATED MODULE: ./test/unit/ts-exts/dep.ts - +// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +(() => { -;// CONCATENATED MODULE: ./test/unit/ts-exts/input.ts +const _depJs = __nccwpck_require__(344); +console.log(_depJs.default); -console.log(dep_dep); +})(); module.exports = __webpack_exports__; /******/ })() diff --git a/test/unit/ts-mixed-modules/output-coverage.js b/test/unit/ts-mixed-modules/output-coverage.js index 48075d4d..a5f8748c 100644 --- a/test/unit/ts-mixed-modules/output-coverage.js +++ b/test/unit/ts-mixed-modules/output-coverage.js @@ -2,13 +2,17 @@ /******/ "use strict"; /******/ var __webpack_modules__ = ({ -/***/ 866: +/***/ 976: /***/ ((module, exports) => { -Object.defineProperty(exports, "__esModule", ({ value: true })); +Object.defineProperty(exports, "__esModule", ({ + value: true +})); const config = { - routes: ['/foo'] + routes: [ + '/foo' + ] }; module.exports = config; @@ -57,7 +61,7 @@ module.exports = config; /******/ // startup /******/ // Load entry module and return exports /******/ // This entry module is referenced by other modules so it can't be inlined -/******/ var __webpack_exports__ = __nccwpck_require__(866); +/******/ var __webpack_exports__ = __nccwpck_require__(976); /******/ module.exports = __webpack_exports__; /******/ /******/ })() diff --git a/test/unit/ts-mixed-modules/output.js b/test/unit/ts-mixed-modules/output.js index d22412d6..fb4f7464 100644 --- a/test/unit/ts-mixed-modules/output.js +++ b/test/unit/ts-mixed-modules/output.js @@ -3,10 +3,12 @@ /******/ var __webpack_modules__ = ({ /***/ 559: -/***/ ((module, __webpack_exports__, __nccwpck_require__) => { +/***/ ((module, exports) => { -__nccwpck_require__.r(__webpack_exports__); -/* module decorator */ module = __nccwpck_require__.hmd(module); + +Object.defineProperty(exports, "__esModule", ({ + value: true +})); const config = { routes: [ '/foo' @@ -15,7 +17,6 @@ const config = { module.exports = config; - /***/ }) /******/ }); @@ -32,8 +33,8 @@ module.exports = config; /******/ } /******/ // Create a new module (and put it into the cache) /******/ var module = __webpack_module_cache__[moduleId] = { -/******/ id: moduleId, -/******/ loaded: false, +/******/ // no module.id needed +/******/ // no module.loaded needed /******/ exports: {} /******/ }; /******/ @@ -46,40 +47,11 @@ module.exports = config; /******/ if(threw) delete __webpack_module_cache__[moduleId]; /******/ } /******/ -/******/ // Flag the module as loaded -/******/ module.loaded = true; -/******/ /******/ // Return the exports of the module /******/ return module.exports; /******/ } /******/ /************************************************************************/ -/******/ /* webpack/runtime/harmony module decorator */ -/******/ (() => { -/******/ __nccwpck_require__.hmd = (module) => { -/******/ module = Object.create(module); -/******/ if (!module.children) module.children = []; -/******/ Object.defineProperty(module, 'exports', { -/******/ enumerable: true, -/******/ set: () => { -/******/ throw new Error('ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: ' + module.id); -/******/ } -/******/ }); -/******/ return module; -/******/ }; -/******/ })(); -/******/ -/******/ /* webpack/runtime/make namespace object */ -/******/ (() => { -/******/ // define __esModule on exports -/******/ __nccwpck_require__.r = (exports) => { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ })(); -/******/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; diff --git a/test/unit/ts-target-es2018/output.js b/test/unit/ts-target-es2018/output.js index e39a893a..5f2aaf14 100644 --- a/test/unit/ts-target-es2018/output.js +++ b/test/unit/ts-target-es2018/output.js @@ -1,11 +1,13 @@ /******/ (() => { // webpackBootstrap +/******/ "use strict"; /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; /******/ /************************************************************************/ var __webpack_exports__ = {}; -if (process?.env.FOO) { + +if (process === null || process === void 0 ? void 0 : process.env.FOO) { console.log('foo'); } diff --git a/test/unit/tsconfig-paths-allowjs/output-coverage.js b/test/unit/tsconfig-paths-allowjs/output-coverage.js index cd8b68e0..4aa0bb3d 100644 --- a/test/unit/tsconfig-paths-allowjs/output-coverage.js +++ b/test/unit/tsconfig-paths-allowjs/output-coverage.js @@ -1,15 +1,10 @@ /******/ (() => { // webpackBootstrap -/******/ "use strict"; /******/ var __webpack_modules__ = ({ -/***/ 306: -/***/ ((__unused_webpack_module, __webpack_exports__, __nccwpck_require__) => { +/***/ 818: +/***/ ((module) => { -__nccwpck_require__.r(__webpack_exports__); -/* harmony export */ __nccwpck_require__.d(__webpack_exports__, { -/* harmony export */ "default": () => (__WEBPACK_DEFAULT_EXPORT__) -/* harmony export */ }); -/* harmony default export */ const __WEBPACK_DEFAULT_EXPORT__ = ({}); +module.exports = eval("require")("../../../../../../../.././module"); /***/ }) @@ -47,47 +42,18 @@ __nccwpck_require__.r(__webpack_exports__); /******/ } /******/ /************************************************************************/ -/******/ /* webpack/runtime/define property getters */ -/******/ (() => { -/******/ // define getter functions for harmony exports -/******/ __nccwpck_require__.d = (exports, definition) => { -/******/ for(var key in definition) { -/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); -/******/ } -/******/ } -/******/ }; -/******/ })(); -/******/ -/******/ /* webpack/runtime/hasOwnProperty shorthand */ -/******/ (() => { -/******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) -/******/ })(); -/******/ -/******/ /* webpack/runtime/make namespace object */ -/******/ (() => { -/******/ // define __esModule on exports -/******/ __nccwpck_require__.r = (exports) => { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ })(); -/******/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; /******/ /************************************************************************/ var __webpack_exports__ = {}; -// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +// This entry need to be wrapped in an IIFE because it need to be in strict mode. (() => { -var exports = __webpack_exports__; +"use strict"; -Object.defineProperty(exports, "__esModule", ({ value: true })); -const _module_1 = __nccwpck_require__(306); -console.log(_module_1.default); +const _module = __nccwpck_require__(818); +console.log(_module.default); })(); diff --git a/test/unit/tsconfig-paths-allowjs/output.js b/test/unit/tsconfig-paths-allowjs/output.js index bc41a94c..9144cafc 100644 --- a/test/unit/tsconfig-paths-allowjs/output.js +++ b/test/unit/tsconfig-paths-allowjs/output.js @@ -1,10 +1,10 @@ /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ -/***/ 17: +/***/ 518: /***/ ((module) => { -module.exports = eval("require")("@module"); +module.exports = eval("require")("../../../../../../../.././module"); /***/ }) @@ -42,46 +42,6 @@ module.exports = eval("require")("@module"); /******/ } /******/ /************************************************************************/ -/******/ /* webpack/runtime/compat get default export */ -/******/ (() => { -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __nccwpck_require__.n = (module) => { -/******/ var getter = module && module.__esModule ? -/******/ () => (module['default']) : -/******/ () => (module); -/******/ __nccwpck_require__.d(getter, { a: getter }); -/******/ return getter; -/******/ }; -/******/ })(); -/******/ -/******/ /* webpack/runtime/define property getters */ -/******/ (() => { -/******/ // define getter functions for harmony exports -/******/ __nccwpck_require__.d = (exports, definition) => { -/******/ for(var key in definition) { -/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); -/******/ } -/******/ } -/******/ }; -/******/ })(); -/******/ -/******/ /* webpack/runtime/hasOwnProperty shorthand */ -/******/ (() => { -/******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) -/******/ })(); -/******/ -/******/ /* webpack/runtime/make namespace object */ -/******/ (() => { -/******/ // define __esModule on exports -/******/ __nccwpck_require__.r = (exports) => { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ })(); -/******/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; @@ -91,11 +51,9 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be in strict mode. (() => { "use strict"; -__nccwpck_require__.r(__webpack_exports__); -/* harmony import */ var _module__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(17); -/* harmony import */ var _module__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(_module__WEBPACK_IMPORTED_MODULE_0__); -console.log((_module__WEBPACK_IMPORTED_MODULE_0___default())); +const _module = __nccwpck_require__(518); +console.log(_module.default); })(); diff --git a/test/unit/tsconfig-paths-conflicting-external/output-coverage.js b/test/unit/tsconfig-paths-conflicting-external/output-coverage.js index acab44d5..4aa0bb3d 100644 --- a/test/unit/tsconfig-paths-conflicting-external/output-coverage.js +++ b/test/unit/tsconfig-paths-conflicting-external/output-coverage.js @@ -1,13 +1,10 @@ /******/ (() => { // webpackBootstrap -/******/ "use strict"; /******/ var __webpack_modules__ = ({ -/***/ 775: -/***/ ((__unused_webpack_module, exports) => { +/***/ 818: +/***/ ((module) => { - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.default = {}; +module.exports = eval("require")("../../../../../../../.././module"); /***/ }) @@ -51,13 +48,12 @@ exports.default = {}; /******/ /************************************************************************/ var __webpack_exports__ = {}; -// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +// This entry need to be wrapped in an IIFE because it need to be in strict mode. (() => { -var exports = __webpack_exports__; +"use strict"; -Object.defineProperty(exports, "__esModule", ({ value: true })); -const _module_1 = __nccwpck_require__(775); -console.log(_module_1.default); +const _module = __nccwpck_require__(818); +console.log(_module.default); })(); diff --git a/test/unit/tsconfig-paths-conflicting-external/output.js b/test/unit/tsconfig-paths-conflicting-external/output.js index bc41a94c..9144cafc 100644 --- a/test/unit/tsconfig-paths-conflicting-external/output.js +++ b/test/unit/tsconfig-paths-conflicting-external/output.js @@ -1,10 +1,10 @@ /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ -/***/ 17: +/***/ 518: /***/ ((module) => { -module.exports = eval("require")("@module"); +module.exports = eval("require")("../../../../../../../.././module"); /***/ }) @@ -42,46 +42,6 @@ module.exports = eval("require")("@module"); /******/ } /******/ /************************************************************************/ -/******/ /* webpack/runtime/compat get default export */ -/******/ (() => { -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __nccwpck_require__.n = (module) => { -/******/ var getter = module && module.__esModule ? -/******/ () => (module['default']) : -/******/ () => (module); -/******/ __nccwpck_require__.d(getter, { a: getter }); -/******/ return getter; -/******/ }; -/******/ })(); -/******/ -/******/ /* webpack/runtime/define property getters */ -/******/ (() => { -/******/ // define getter functions for harmony exports -/******/ __nccwpck_require__.d = (exports, definition) => { -/******/ for(var key in definition) { -/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); -/******/ } -/******/ } -/******/ }; -/******/ })(); -/******/ -/******/ /* webpack/runtime/hasOwnProperty shorthand */ -/******/ (() => { -/******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) -/******/ })(); -/******/ -/******/ /* webpack/runtime/make namespace object */ -/******/ (() => { -/******/ // define __esModule on exports -/******/ __nccwpck_require__.r = (exports) => { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ })(); -/******/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; @@ -91,11 +51,9 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be in strict mode. (() => { "use strict"; -__nccwpck_require__.r(__webpack_exports__); -/* harmony import */ var _module__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(17); -/* harmony import */ var _module__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(_module__WEBPACK_IMPORTED_MODULE_0__); -console.log((_module__WEBPACK_IMPORTED_MODULE_0___default())); +const _module = __nccwpck_require__(518); +console.log(_module.default); })(); diff --git a/test/unit/tsconfig-paths/output-coverage.js b/test/unit/tsconfig-paths/output-coverage.js index 5d9a60e1..4aa0bb3d 100644 --- a/test/unit/tsconfig-paths/output-coverage.js +++ b/test/unit/tsconfig-paths/output-coverage.js @@ -1,13 +1,10 @@ /******/ (() => { // webpackBootstrap -/******/ "use strict"; /******/ var __webpack_modules__ = ({ -/***/ 520: -/***/ ((__unused_webpack_module, exports) => { +/***/ 818: +/***/ ((module) => { - -Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.default = {}; +module.exports = eval("require")("../../../../../../../.././module"); /***/ }) @@ -51,13 +48,12 @@ exports.default = {}; /******/ /************************************************************************/ var __webpack_exports__ = {}; -// This entry need to be wrapped in an IIFE because it need to be isolated against other modules in the chunk. +// This entry need to be wrapped in an IIFE because it need to be in strict mode. (() => { -var exports = __webpack_exports__; +"use strict"; -Object.defineProperty(exports, "__esModule", ({ value: true })); -const _module_1 = __nccwpck_require__(520); -console.log(_module_1.default); +const _module = __nccwpck_require__(818); +console.log(_module.default); })(); diff --git a/test/unit/tsconfig-paths/output.js b/test/unit/tsconfig-paths/output.js index bc41a94c..9144cafc 100644 --- a/test/unit/tsconfig-paths/output.js +++ b/test/unit/tsconfig-paths/output.js @@ -1,10 +1,10 @@ /******/ (() => { // webpackBootstrap /******/ var __webpack_modules__ = ({ -/***/ 17: +/***/ 518: /***/ ((module) => { -module.exports = eval("require")("@module"); +module.exports = eval("require")("../../../../../../../.././module"); /***/ }) @@ -42,46 +42,6 @@ module.exports = eval("require")("@module"); /******/ } /******/ /************************************************************************/ -/******/ /* webpack/runtime/compat get default export */ -/******/ (() => { -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __nccwpck_require__.n = (module) => { -/******/ var getter = module && module.__esModule ? -/******/ () => (module['default']) : -/******/ () => (module); -/******/ __nccwpck_require__.d(getter, { a: getter }); -/******/ return getter; -/******/ }; -/******/ })(); -/******/ -/******/ /* webpack/runtime/define property getters */ -/******/ (() => { -/******/ // define getter functions for harmony exports -/******/ __nccwpck_require__.d = (exports, definition) => { -/******/ for(var key in definition) { -/******/ if(__nccwpck_require__.o(definition, key) && !__nccwpck_require__.o(exports, key)) { -/******/ Object.defineProperty(exports, key, { enumerable: true, get: definition[key] }); -/******/ } -/******/ } -/******/ }; -/******/ })(); -/******/ -/******/ /* webpack/runtime/hasOwnProperty shorthand */ -/******/ (() => { -/******/ __nccwpck_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop)) -/******/ })(); -/******/ -/******/ /* webpack/runtime/make namespace object */ -/******/ (() => { -/******/ // define __esModule on exports -/******/ __nccwpck_require__.r = (exports) => { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); -/******/ }; -/******/ })(); -/******/ /******/ /* webpack/runtime/compat */ /******/ /******/ if (typeof __nccwpck_require__ !== 'undefined') __nccwpck_require__.ab = __dirname + "/"; @@ -91,11 +51,9 @@ var __webpack_exports__ = {}; // This entry need to be wrapped in an IIFE because it need to be in strict mode. (() => { "use strict"; -__nccwpck_require__.r(__webpack_exports__); -/* harmony import */ var _module__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(17); -/* harmony import */ var _module__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(_module__WEBPACK_IMPORTED_MODULE_0__); -console.log((_module__WEBPACK_IMPORTED_MODULE_0___default())); +const _module = __nccwpck_require__(518); +console.log(_module.default); })();