Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhance: upgrade local ts #674

Merged
merged 10 commits into from
Apr 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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