diff --git a/dist-raw/node-package-json-reader.js b/dist-raw/node-package-json-reader.js index 1c36501cd..e9f82c6f4 100644 --- a/dist-raw/node-package-json-reader.js +++ b/dist-raw/node-package-json-reader.js @@ -5,6 +5,7 @@ const { SafeMap } = require('./node-primordials'); const { internalModuleReadJSON } = require('./node-internal-fs'); const { pathToFileURL } = require('url'); const { toNamespacedPath } = require('path'); +// const { getOptionValue } = require('./node-options'); const cache = new SafeMap(); @@ -23,7 +24,6 @@ function read(jsonPath) { toNamespacedPath(jsonPath) ); const result = { string, containsKeys }; - const { getOptionValue } = require('./node-options'); if (string !== undefined) { if (manifest === undefined) { // manifest = getOptionValue('--experimental-policy') ? diff --git a/src/test/regression.spec.ts b/src/test/regression.spec.ts new file mode 100644 index 000000000..db3c44649 --- /dev/null +++ b/src/test/regression.spec.ts @@ -0,0 +1,39 @@ +// Misc regression tests go here if they do not have a better home + +import * as exp from 'expect'; +import { join } from 'path'; +import { createExec, createExecTester } from './exec-helpers'; +import { + CMD_TS_NODE_WITHOUT_PROJECT_FLAG, + contextTsNodeUnderTest, + TEST_DIR, +} from './helpers'; +import { test as _test } from './testlib'; + +const test = _test.context(contextTsNodeUnderTest); +const exec = createExecTester({ + exec: createExec({ + cwd: TEST_DIR, + }), +}); + +test('#1488 regression test', async () => { + // Scenario that caused the bug: + // `allowJs` turned on + // `skipIgnore` turned on so that ts-node tries to compile itself (not ideal but theoretically we should be ok with this) + // Attempt to `require()` a `.js` file + // `assertScriptCanLoadAsCJS` is triggered within `require()` + // `./package.json` needs to be fetched into cache via `assertScriptCanLoadAsCJS` which caused a recursive `require()` call + // Circular dependency warning is emitted by node + + const { stdout, stderr } = await exec({ + exec: createExec({ + cwd: join(TEST_DIR, '1488'), + }), + cmd: `${CMD_TS_NODE_WITHOUT_PROJECT_FLAG} ./index.js`, + }); + + // Assert that we do *not* get `Warning: Accessing non-existent property 'getOptionValue' of module exports inside circular dependency` + exp(stdout).toBe('foo\n'); // prove that it ran + exp(stderr).toBe(''); // prove that no warnings +}); diff --git a/tests/1488/index.js b/tests/1488/index.js new file mode 100644 index 000000000..81afa3157 --- /dev/null +++ b/tests/1488/index.js @@ -0,0 +1 @@ +console.log('foo'); diff --git a/tests/1488/package.json b/tests/1488/package.json new file mode 100644 index 000000000..0967ef424 --- /dev/null +++ b/tests/1488/package.json @@ -0,0 +1 @@ +{} diff --git a/tests/1488/tsconfig.json b/tests/1488/tsconfig.json new file mode 100644 index 000000000..7a37a1fad --- /dev/null +++ b/tests/1488/tsconfig.json @@ -0,0 +1,8 @@ +{ + "compilerOptions": { + "allowJs": true + }, + "ts-node": { + "skipIgnore": true + } +}