Skip to content

Commit

Permalink
enhance: upgrade local ts (#674)
Browse files Browse the repository at this point in the history
Fixes #606

* bump ts-loader version
* bump built-in ts version
* override `incremental` option to `false`

Co-authored-by: Steven <steven@ceriously.com>
  • Loading branch information
huozhi and styfle committed Apr 5, 2021
1 parent 6c11412 commit 6f4714d
Show file tree
Hide file tree
Showing 10 changed files with 3,889 additions and 3,517 deletions.
4 changes: 2 additions & 2 deletions package.json
Expand Up @@ -99,11 +99,11 @@
"terser": "^5.6.1",
"the-answer": "^1.0.0",
"tiny-json-http": "^7.0.2",
"ts-loader": "^5.3.1",
"ts-loader": "^6.1.2",
"tsconfig-paths": "^3.7.0",
"tsconfig-paths-webpack-plugin": "^3.2.0",
"twilio": "^3.23.2",
"typescript": "^3.2.2",
"typescript": "^3.9.9",
"vm2": "^3.6.6",
"vue": "^2.5.17",
"vue-server-renderer": "^2.5.17",
Expand Down
10 changes: 6 additions & 4 deletions src/index.js
Expand Up @@ -70,9 +70,6 @@ function ncc (
conditionNames: ["import", "node", production ? "production": "development"]
});

process.env.__NCC_OPTS = JSON.stringify({
quiet
});
const ext = extname(filename);

if (!quiet) {
Expand All @@ -85,7 +82,11 @@ function ncc (
}

const resolvedEntry = resolve.sync(entry);
process.env.TYPESCRIPT_LOOKUP_PATH = resolvedEntry;
process.env.__NCC_OPTS = JSON.stringify({
quiet,
typescriptLookupPath: resolvedEntry,
});

const shebangMatch = fs.readFileSync(resolvedEntry).toString().match(shebangRegEx);
const mfs = new MemoryFS();

Expand Down Expand Up @@ -321,6 +322,7 @@ function ncc (
allowSyntheticDefaultImports: true,
module: 'esnext',
outDir: '//',
incremental: false,
noEmit: false
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/typescript.js
@@ -1,8 +1,8 @@

const { Module } = require('module');
const m = new Module('', null);
const {quiet} = JSON.parse(process.env.__NCC_OPTS || '{}');
m.paths = Module._nodeModulePaths(process.env.TYPESCRIPT_LOOKUP_PATH || (process.cwd() + '/'));
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');
Expand Down
9 changes: 9 additions & 0 deletions test/cli.js
Expand Up @@ -94,5 +94,14 @@
stdout = stdout.toString().replace(/[\r\n\s]/g, '').trim();
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;
},
}
]
3 changes: 2 additions & 1 deletion test/index.test.js
Expand Up @@ -84,7 +84,8 @@ for (const unitTest of fs.readdirSync(`${__dirname}/unit`)) {
for (const cliTest of eval(fs.readFileSync(__dirname + "/cli.js").toString())) {
it(`should execute "ncc ${(cliTest.args || []).join(" ")}"`, async () => {
const ps = fork(__dirname + (coverage ? "/../src/cli.js" : "/../dist/ncc/cli.js"), cliTest.args || [], {
stdio: "pipe"
stdio: "pipe",
env: { ...process.env, ...cliTest.env },
});
let stderr = "", stdout = "";
ps.stderr.on("data", chunk => stderr += chunk.toString());
Expand Down
1 change: 0 additions & 1 deletion test/integration/node_modules/typescript/index.js

This file was deleted.

1 change: 1 addition & 0 deletions test/integration/node_modules/typescript/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 4 additions & 3 deletions test/unit/bundle-subasset2/output-coverage.js
Expand Up @@ -85,10 +85,11 @@ var external_piscina_default = /*#__PURE__*/__nccwpck_require__.n(external_pisci
const external_path_namespaceObject = require("path");
;// CONCATENATED MODULE: ./test/unit/bundle-subasset2/input.ts
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Expand Down Expand Up @@ -122,7 +123,7 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod


var piscina = new (external_piscina_default())({
filename: __nccwpck_require__.ab + "pi-bridge.js"
filename: __nccwpck_require__.ab + "pi-bridge.js",
});
(function () {
return __awaiter(this, void 0, void 0, function () {
Expand All @@ -141,4 +142,4 @@ var piscina = new (external_piscina_default())({

module.exports = __webpack_exports__;
/******/ })()
;
;
7 changes: 4 additions & 3 deletions test/unit/bundle-subasset2/output.js
Expand Up @@ -85,10 +85,11 @@ var external_piscina_default = /*#__PURE__*/__nccwpck_require__.n(external_pisci
const external_path_namespaceObject = require("path");
;// CONCATENATED MODULE: ./test/unit/bundle-subasset2/input.ts
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Expand Down Expand Up @@ -122,7 +123,7 @@ var __generator = (undefined && undefined.__generator) || function (thisArg, bod


var piscina = new (external_piscina_default())({
filename: __nccwpck_require__.ab + "pi-bridge.js"
filename: __nccwpck_require__.ab + "pi-bridge.js",
});
(function () {
return __awaiter(this, void 0, void 0, function () {
Expand All @@ -141,4 +142,4 @@ var piscina = new (external_piscina_default())({

module.exports = __webpack_exports__;
/******/ })()
;
;
1 change: 1 addition & 0 deletions test/unit/ts-exts/tsconfig.json
Expand Up @@ -3,6 +3,7 @@
"module": "commonjs",
"moduleResolution": "node",
"baseUrl": ".",
"incremental": true,
"paths": {
"@*": ["./*"]
}
Expand Down

0 comments on commit 6f4714d

Please sign in to comment.