Comparing version
@@ -265,3 +265,3 @@ "use strict"; | ||
getProjectVersion: () => String(projectVersion), | ||
getScriptFileNames: () => rootFileNames, | ||
getScriptFileNames: () => Array.from(fileContents.keys()), | ||
getScriptVersion: (fileName) => { | ||
@@ -298,23 +298,15 @@ const version = fileVersions.get(fileName); | ||
const updateMemoryCache = (contents, fileName) => { | ||
let shouldIncrementProjectVersion = false; | ||
const fileVersion = fileVersions.get(fileName) || 0; | ||
const isFileInCache = fileVersion !== 0; | ||
// Add to `rootFiles` when discovered for the first time. | ||
if (!isFileInCache) { | ||
if (fileVersion === 0) { | ||
rootFileNames.push(fileName); | ||
// Modifying rootFileNames means a project change | ||
shouldIncrementProjectVersion = true; | ||
} | ||
const previousContents = fileContents.get(fileName); | ||
// Avoid incrementing cache when nothing has changed. | ||
if (previousContents !== contents) { | ||
if (contents !== previousContents) { | ||
fileVersions.set(fileName, fileVersion + 1); | ||
fileContents.set(fileName, contents); | ||
// Only bump project version when file is modified in cache, not when discovered for the first time | ||
if (isFileInCache) { | ||
shouldIncrementProjectVersion = true; | ||
} | ||
// Increment project version for every file change. | ||
projectVersion++; | ||
} | ||
if (shouldIncrementProjectVersion) | ||
projectVersion++; | ||
}; | ||
@@ -321,0 +313,0 @@ let previousProgram = undefined; |
@@ -12,6 +12,7 @@ "use strict"; | ||
const PROJECT = path_1.join(TEST_DIR, 'tsconfig.json'); | ||
const BIN_EXEC = `node "${path_1.join(__dirname, '../dist/bin')}" --project "${PROJECT}"`; | ||
const SCRIPT_EXEC = `node "${path_1.join(__dirname, '../dist/bin-script')}"`; | ||
const BIN_PATH = path_1.join(__dirname, '../dist/bin'); | ||
const BIN_SCRIPT_PATH = path_1.join(__dirname, '../dist/bin-script'); | ||
const SOURCE_MAP_REGEXP = /\/\/# sourceMappingURL=data:application\/json;charset=utf\-8;base64,[\w\+]+=*$/; | ||
describe('ts-node', function () { | ||
const cmd = `node "${BIN_PATH}" --project "${PROJECT}"`; | ||
this.timeout(10000); | ||
@@ -24,3 +25,3 @@ it('should export the correct version', function () { | ||
it('should execute cli', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} tests/hello-world`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} tests/hello-world`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -41,3 +42,3 @@ chai_1.expect(stdout).to.equal('Hello, world!\n'); | ||
it('should execute cli with absolute path', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} "${path_1.join(TEST_DIR, 'hello-world')}"`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} "${path_1.join(TEST_DIR, 'hello-world')}"`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -49,3 +50,3 @@ chai_1.expect(stdout).to.equal('Hello, world!\n'); | ||
it('should print scripts', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} -pe "import { example } from './tests/complex/index';example()"`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} -pe "import { example } from './tests/complex/index';example()"`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -57,3 +58,3 @@ chai_1.expect(stdout).to.equal('example\n'); | ||
it('should provide registered information globally', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} tests/env`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} tests/env`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -76,3 +77,3 @@ chai_1.expect(stdout).to.equal('object\n'); | ||
child_process_1.exec([ | ||
BIN_EXEC, | ||
cmd, | ||
'-O "{\\\"allowJs\\\":true}"', | ||
@@ -88,3 +89,3 @@ '-pe "import { main } from \'./tests/allow-js/run\';main()"' | ||
child_process_1.exec([ | ||
BIN_EXEC, | ||
cmd, | ||
'-O "{\\\"allowJs\\\":true}"', | ||
@@ -100,3 +101,3 @@ '-pe "import { Foo2 } from \'./tests/allow-js/with-jsx\'; Foo2.sayHi()"' | ||
it('should eval code', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} -e "import * as m from './tests/module';console.log(m.example('test'))"`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} -e "import * as m from './tests/module';console.log(m.example('test'))"`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -108,3 +109,3 @@ chai_1.expect(stdout).to.equal('TEST\n'); | ||
it('should import empty files', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} -e "import './tests/empty'"`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} -e "import './tests/empty'"`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -116,3 +117,3 @@ chai_1.expect(stdout).to.equal(''); | ||
it('should throw errors', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} -e "import * as m from './tests/module';console.log(m.example(123))"`, function (err) { | ||
child_process_1.exec(`${cmd} -e "import * as m from './tests/module';console.log(m.example(123))"`, function (err) { | ||
if (err === null) { | ||
@@ -127,3 +128,3 @@ return done('Command was expected to fail, but it succeeded.'); | ||
it('should be able to ignore diagnostic', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} --ignore-diagnostics 2345 -e "import * as m from './tests/module';console.log(m.example(123))"`, function (err) { | ||
child_process_1.exec(`${cmd} --ignore-diagnostics 2345 -e "import * as m from './tests/module';console.log(m.example(123))"`, function (err) { | ||
if (err === null) { | ||
@@ -137,3 +138,3 @@ return done('Command was expected to fail, but it succeeded.'); | ||
it('should work with source maps', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} tests/throw`, function (err) { | ||
child_process_1.exec(`${cmd} tests/throw`, function (err) { | ||
if (err === null) { | ||
@@ -152,3 +153,3 @@ return done('Command was expected to fail, but it succeeded.'); | ||
it('eval should work with source maps', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} -pe "import './tests/throw'"`, function (err) { | ||
child_process_1.exec(`${cmd} -pe "import './tests/throw'"`, function (err) { | ||
if (err === null) { | ||
@@ -166,3 +167,3 @@ return done('Command was expected to fail, but it succeeded.'); | ||
it('should support transpile only mode', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} --transpile-only -pe "x"`, function (err) { | ||
child_process_1.exec(`${cmd} --transpile-only -pe "x"`, function (err) { | ||
if (err === null) { | ||
@@ -176,3 +177,3 @@ return done('Command was expected to fail, but it succeeded.'); | ||
it('should throw error even in transpileOnly mode', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} --transpile-only -pe "console."`, function (err) { | ||
child_process_1.exec(`${cmd} --transpile-only -pe "console."`, function (err) { | ||
if (err === null) { | ||
@@ -186,3 +187,3 @@ return done('Command was expected to fail, but it succeeded.'); | ||
it('should pipe into `ts-node` and evaluate', function (done) { | ||
const cp = child_process_1.exec(BIN_EXEC, function (err, stdout) { | ||
const cp = child_process_1.exec(cmd, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -195,3 +196,3 @@ chai_1.expect(stdout).to.equal('hello\n'); | ||
it('should pipe into `ts-node`', function (done) { | ||
const cp = child_process_1.exec(`${BIN_EXEC} -p`, function (err, stdout) { | ||
const cp = child_process_1.exec(`${cmd} -p`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -204,3 +205,3 @@ chai_1.expect(stdout).to.equal('true\n'); | ||
it('should pipe into an eval script', function (done) { | ||
const cp = child_process_1.exec(`${BIN_EXEC} --transpile-only -pe 'process.stdin.isTTY'`, function (err, stdout) { | ||
const cp = child_process_1.exec(`${cmd} --transpile-only -pe 'process.stdin.isTTY'`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -213,3 +214,3 @@ chai_1.expect(stdout).to.equal('undefined\n'); | ||
it('should support require flags', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} -r ./tests/hello-world -pe "console.log('success')"`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} -r ./tests/hello-world -pe "console.log('success')"`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -221,3 +222,3 @@ chai_1.expect(stdout).to.equal('Hello, world!\nsuccess\nundefined\n'); | ||
it('should support require from node modules', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} -r typescript -e "console.log('success')"`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} -r typescript -e "console.log('success')"`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -229,3 +230,3 @@ chai_1.expect(stdout).to.equal('success\n'); | ||
it.skip('should use source maps with react tsx', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} -r ./tests/emit-compiled.ts tests/jsx-react.tsx`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} -r ./tests/emit-compiled.ts tests/jsx-react.tsx`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -237,3 +238,3 @@ chai_1.expect(stdout).to.equal('todo'); | ||
it('should allow custom typings', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} tests/custom-types`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} tests/custom-types`, function (err, stdout) { | ||
chai_1.expect(err).to.match(/Error: Cannot find module 'does-not-exist'/); | ||
@@ -244,3 +245,3 @@ return done(); | ||
it('should preserve `ts-node` context with child process', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} tests/child-process`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} tests/child-process`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -252,3 +253,3 @@ chai_1.expect(stdout).to.equal('Hello, world!\n'); | ||
it('should import js before ts by default', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} tests/import-order/compiled`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} tests/import-order/compiled`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -260,3 +261,3 @@ chai_1.expect(stdout).to.equal('Hello, JavaScript!\n'); | ||
it('should import ts before js when --prefer-ts-exts flag is present', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} --prefer-ts-exts tests/import-order/compiled`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} --prefer-ts-exts tests/import-order/compiled`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -268,3 +269,3 @@ chai_1.expect(stdout).to.equal('Hello, TypeScript!\n'); | ||
it('should import ts before js when TS_NODE_PREFER_TS_EXTS env is present', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} tests/import-order/compiled`, { env: Object.assign(Object.assign({}, process.env), { TS_NODE_PREFER_TS_EXTS: 'true' }) }, function (err, stdout) { | ||
child_process_1.exec(`${cmd} tests/import-order/compiled`, { env: Object.assign(Object.assign({}, process.env), { TS_NODE_PREFER_TS_EXTS: 'true' }) }, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -276,3 +277,3 @@ chai_1.expect(stdout).to.equal('Hello, TypeScript!\n'); | ||
it('should ignore .d.ts files', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} tests/import-order/importer`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} tests/import-order/importer`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -283,5 +284,12 @@ chai_1.expect(stdout).to.equal('Hello, World!\n'); | ||
}); | ||
it('issue #884', function (done) { | ||
child_process_1.exec(`node "${BIN_PATH}" --project tests/issue-884/tsconfig.json tests/issue-884`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
chai_1.expect(stdout).to.equal(''); | ||
return done(); | ||
}); | ||
}); | ||
if (semver.gte(ts.version, '2.7.0')) { | ||
it('should support script mode', function (done) { | ||
child_process_1.exec(`${SCRIPT_EXEC} tests/scope/a/log`, function (err, stdout) { | ||
child_process_1.exec(`node ${BIN_SCRIPT_PATH} tests/scope/a/log`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -346,3 +354,3 @@ chai_1.expect(stdout).to.equal('.ts\n'); | ||
it('should execute cli', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} --compiler-host tests/hello-world`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} --compiler-host tests/hello-world`, function (err, stdout) { | ||
chai_1.expect(err).to.equal(null); | ||
@@ -354,3 +362,3 @@ chai_1.expect(stdout).to.equal('Hello, world!\n'); | ||
it('should give ts error for invalid node_modules', function (done) { | ||
child_process_1.exec(`${BIN_EXEC} --compiler-host --skip-ignore tests/from-node-modules`, function (err, stdout) { | ||
child_process_1.exec(`${cmd} --compiler-host --skip-ignore tests/from-node-modules`, function (err, stdout) { | ||
if (err === null) | ||
@@ -357,0 +365,0 @@ return done('Expected an error'); |
{ | ||
"name": "ts-node", | ||
"version": "8.7.0", | ||
"version": "8.8.0", | ||
"description": "TypeScript execution environment and REPL for node.js, with source map support", | ||
@@ -60,7 +60,7 @@ "main": "dist/index.js", | ||
"@types/diff": "^4.0.2", | ||
"@types/mocha": "^5.0.0", | ||
"@types/node": "^12.7.12", | ||
"@types/mocha": "^5.2.7", | ||
"@types/node": "^13.9.2", | ||
"@types/proxyquire": "^1.3.28", | ||
"@types/react": "^16.0.2", | ||
"@types/semver": "^6.0.0", | ||
"@types/semver": "^7.1.0", | ||
"@types/source-map-support": "^0.5.0", | ||
@@ -70,3 +70,3 @@ "axios": "^0.19.0", | ||
"istanbul": "^0.4.0", | ||
"mocha": "^6.1.4", | ||
"mocha": "^6.2.2", | ||
"ntypescript": "^1.201507091536.1", | ||
@@ -76,7 +76,7 @@ "proxyquire": "^2.0.0", | ||
"rimraf": "^3.0.0", | ||
"semver": "^6.1.0", | ||
"tslint": "^5.11.0", | ||
"semver": "^7.1.3", | ||
"tslint": "^6.1.0", | ||
"tslint-config-standard": "^9.0.0", | ||
"typescript": "^3.7.2", | ||
"typescript-json-schema": "0.40.0" | ||
"typescript-json-schema": "^0.42.0" | ||
}, | ||
@@ -83,0 +83,0 @@ "peerDependencies": { |
@@ -1,2 +0,2 @@ | ||
#  | ||
#  | ||
@@ -3,0 +3,0 @@ [![NPM version][npm-image]][npm-url] |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
1
-50%245824
-0.09%