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

fix: support type: module in Node.js 16.17.0+ and 18.6.0+ #23637

Merged
merged 8 commits into from
Sep 7, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion npm/vite-dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"dedent": "^0.7.0",
"mocha": "^9.2.2",
"sinon": "^13.0.1",
"ts-node": "^10.2.1",
"ts-node": "^10.9.1",
"vite": "3.0.3",
"vite-plugin-inspect": "0.4.3"
},
Expand Down
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"proxyquire": "2.1.3",
"sinon": "^13.0.1",
"snap-shot-it": "^7.9.6",
"ts-node": "^10.2.1",
"ts-node": "^10.9.1",
"webpack": "npm:webpack@^5",
"webpack-4": "npm:webpack@^4",
"webpack-dev-server-3": "npm:webpack-dev-server@^3"
Expand Down
2 changes: 1 addition & 1 deletion npm/webpack-preprocessor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"sinon": "^9.0.0",
"sinon-chai": "^3.5.0",
"snap-shot-it": "7.9.2",
"ts-node": "^10.2.1",
"ts-node": "^10.9.1",
"webpack": "^4.44.2"
},
"peerDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@
"through": "2.3.8",
"through2": "^4.0.2",
"tree-kill": "1.2.2",
"ts-node": "^10.2.1",
"ts-node": "^10.9.1",
"typescript": "^4.7.4",
"yarn-deduplicate": "3.1.0"
},
Expand Down
5 changes: 5 additions & 0 deletions packages/data-context/src/data/ProjectConfigIpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,9 @@ export class ProjectConfigIpc extends EventEmitter {
// ts-node for CommonJS
// ts-node/esm for ESM
if (hasTypeScriptInstalled(this.projectRoot)) {
debug('found typescript in %s', this.projectRoot)
if (isProjectUsingESModules) {
debug(`using --experimental-specifier-resolution=node with --loader ${tsNodeEsm}`)
// Use the ts-node/esm loader so they can use TypeScript with `"type": "module".
// The loader API is experimental and will change.
// The same can be said for the other alternative, esbuild, so this is the
Expand All @@ -294,6 +296,8 @@ export class ProjectConfigIpc extends EventEmitter {
// so we need to load and evaluate the hook first using the `--require` module API.
const tsNodeLoader = `--require "${tsNode}"`

debug(`using cjs with --require ${tsNode}`)

if (childOptions.env.NODE_OPTIONS) {
childOptions.env.NODE_OPTIONS += ` ${tsNodeLoader}`
} else {
Expand All @@ -303,6 +307,7 @@ export class ProjectConfigIpc extends EventEmitter {
} else {
// Just use Node's built-in ESM support.
// TODO: Consider using userland `esbuild` with Node's --loader API to handle ESM.
debug(`no typescript found, just use regular Node.js`)
}

return fork(CHILD_PROCESS_FILE_PATH, configProcessArgs, childOptions)
Expand Down
2 changes: 1 addition & 1 deletion packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"tough-cookie": "4.0.0",
"trash": "5.2.0",
"tree-kill": "1.2.2",
"ts-node": "^10.2.1",
"ts-node": "^10.9.1",
"tslib": "2.3.1",
"underscore.string": "3.3.5",
"url-parse": "1.5.9",
Expand Down
2 changes: 1 addition & 1 deletion packages/ts/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
},
"dependencies": {
"debug": "^4.3.2",
"ts-node": "^10.2.1",
"ts-node": "^10.9.1",
"tslib": "2.3.1",
"typescript-cached-transpile": "^0.0.6"
},
Expand Down
5 changes: 4 additions & 1 deletion system-tests/scripts/bootstrap-docker-container.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ export CYPRESS_CACHE_FOLDER=/tmp/CYPRESS_CACHE_FOLDER/
export npm_config_cache=/tmp/npm_config_cache/
export npm_config_package_lock=false

mkdir $npm_config_cache
chown -R 1000:1000 $npm_config_cache
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we do need the chown, I think this would be safer, since the uid/gid aren't guaranteed to always be 1000:1000. But maybe this is wrong, considering what happened when this line was deleted, could be some trickery afoot.

Suggested change
chown -R 1000:1000 $npm_config_cache
chown -R $(id -u):$(id -g) $npm_config_cache

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interestingly enough this also is not working 🤔

https://app.circleci.com/pipelines/github/cypress-io/cypress/42940/workflows/4929e8f3-cf0b-4e98-b1ae-4b5c6c83f6f0/jobs/1788721

Will ssh in and see what the output of id -u and id -g is.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

circleci@ip-172-28-37-251:~$ id -u
1000
circleci@ip-172-28-37-251:~$ id -g
1000

Hmmmm.

Copy link
Contributor Author

@lmiller1990 lmiller1990 Sep 6, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, chown -R $(id -u):$(id -g) $npm_config_cache is just not valid code. Try running it. chown: missing operand after ‘1000:1000.

Let's do...

uid=$(id -u)
gid=$(id -g)

chown -R $uid:$gui $npm_config_cache

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works for me on Linux in bash and zsh. You do have a slight typo, gid => gui

This script runs in the context of the Docker container too, not the main system... and id -u and id -g work, but by default we're running as root:
image

So now I'm even more confused why 1000:1000 is needed/works here, as we are running as root already.... 🤔 🤔 🤔


npx npm@latest install --unsafe-perm --allow-root --force file:$CLI_PATH

PATH=$PATH:./node_modules/.bin
Expand All @@ -52,4 +55,4 @@ set -e
cd -
rm -rf $TEST_PROJECT_DIR

exit $EXIT_CODE
exit $EXIT_CODE
17 changes: 17 additions & 0 deletions system-tests/test-binary/node_versions_spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,20 @@ describe('binary node versions', () => {
'cypress/base:17.3.0',
].forEach(smokeTestDockerImage)
})

describe('type: module', () => {
[
'cypress/base:16.17.0',
'cypress/base:18.6.0',
].forEach((dockerImage) => {
systemTests.it(`can run in ${dockerImage}`, {
withBinary: true,
project: 'config-cjs-and-esm/config-with-ts-module',
dockerImage,
testingType: 'e2e',
spec: 'app.cy.js',
browser: 'electron',
expectedExitCode: 0,
})
})
})
43 changes: 19 additions & 24 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2293,17 +2293,12 @@
resolved "https://registry.yarnpkg.com/@coolaj86/urequest/-/urequest-1.3.7.tgz#66a1d66378dd6534e9c8e68948bf09acf32bab77"
integrity sha512-PPrVYra9aWvZjSCKl/x1pJ9ZpXda1652oJrPBYy5rQumJJMkmTBN3ux+sK2xAUwVvv2wnewDlaQaHLxLwSHnIA==

"@cspotcode/source-map-consumer@0.8.0":
version "0.8.0"
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-consumer/-/source-map-consumer-0.8.0.tgz#33bf4b7b39c178821606f669bbc447a6a629786b"
integrity sha512-41qniHzTU8yAGbCp04ohlmSrZf8bkf/iJsl3V0dRGsQN/5GFfx+LbCSsCpp2gqrqjTVg/K6O8ycoV35JIwAzAg==

"@cspotcode/source-map-support@0.7.0":
version "0.7.0"
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.7.0.tgz#4789840aa859e46d2f3173727ab707c66bf344f5"
integrity sha512-X4xqRHqN8ACt2aHVe51OxeA2HjbcL4MqFqXkrmQszJ1NOUuUu5u6Vqx/0lZSVNku7velL5FC/s5uEAj1lsBMhA==
"@cspotcode/source-map-support@^0.8.0":
version "0.8.1"
resolved "https://registry.yarnpkg.com/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz#00629c35a688e05a88b1cda684fb9d5e73f000a1"
integrity sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==
dependencies:
"@cspotcode/source-map-consumer" "0.8.0"
"@jridgewell/trace-mapping" "0.3.9"

"@csstools/convert-colors@^1.4.0":
version "1.4.0"
Expand Down Expand Up @@ -4150,10 +4145,10 @@
resolved "https://registry.yarnpkg.com/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.10.tgz#baf57b4e2a690d4f38560171f91783656b7f8186"
integrity sha512-Ht8wIW5v165atIX1p+JvKR5ONzUyF4Ac8DZIQ5kZs9zrb6M8SJNXpx1zn04rn65VjBMygRoMXcyYwNK0fT7bEg==

"@jridgewell/trace-mapping@^0.3.0":
version "0.3.4"
resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.4.tgz#f6a0832dffd5b8a6aaa633b7d9f8e8e94c83a0c3"
integrity sha512-vFv9ttIedivx0ux3QSjhgtCVjPZd5l46ZOMDSCwnH1yUO2e964gO8LZGyv2QkqcgR6TnBU1v+1IFqmeoG+0UJQ==
"@jridgewell/trace-mapping@0.3.9", "@jridgewell/trace-mapping@^0.3.0":
version "0.3.9"
resolved "https://registry.yarnpkg.com/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz#6534fd5933a53ba7cbf3a17615e273a0d1273ff9"
integrity sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==
dependencies:
"@jridgewell/resolve-uri" "^3.0.3"
"@jridgewell/sourcemap-codec" "^1.4.10"
Expand Down Expand Up @@ -32744,12 +32739,12 @@ ts-log@^2.2.3:
resolved "https://registry.yarnpkg.com/ts-log/-/ts-log-2.2.3.tgz#4da5640fe25a9fb52642cd32391c886721318efb"
integrity sha512-XvB+OdKSJ708Dmf9ore4Uf/q62AYDTzFcAdxc8KNML1mmAWywRFVt/dn1KYJH8Agt5UJNujfM3znU5PxgAzA2w==

ts-node@^10.2.1:
version "10.7.0"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.7.0.tgz#35d503d0fab3e2baa672a0e94f4b40653c2463f5"
integrity sha512-TbIGS4xgJoX2i3do417KSaep1uRAW/Lu+WAL2doDHC0D6ummjirVOXU5/7aiZotbQ5p1Zp9tP7U6cYhA0O7M8A==
ts-node@^10.9.1:
version "10.9.1"
resolved "https://registry.yarnpkg.com/ts-node/-/ts-node-10.9.1.tgz#e73de9102958af9e1f0b168a6ff320e25adcff4b"
integrity sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==
dependencies:
"@cspotcode/source-map-support" "0.7.0"
"@cspotcode/source-map-support" "^0.8.0"
"@tsconfig/node10" "^1.0.7"
"@tsconfig/node12" "^1.0.7"
"@tsconfig/node14" "^1.0.0"
Expand All @@ -32760,7 +32755,7 @@ ts-node@^10.2.1:
create-require "^1.1.0"
diff "^4.0.1"
make-error "^1.1.1"
v8-compile-cache-lib "^3.0.0"
v8-compile-cache-lib "^3.0.1"
yn "3.1.1"

ts-node@^9:
Expand Down Expand Up @@ -33651,10 +33646,10 @@ uuid@^3.0.0, uuid@^3.0.1, uuid@^3.3.2, uuid@^3.4.0:
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==

v8-compile-cache-lib@^3.0.0:
version "3.0.0"
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.0.tgz#0582bcb1c74f3a2ee46487ceecf372e46bce53e8"
integrity sha512-mpSYqfsFvASnSn5qMiwrr4VKfumbPyONLCOPmsR3A6pTY/r0+tSaVbgPWSAIuzbk3lCTa+FForeTiO+wBQGkjA==
v8-compile-cache-lib@^3.0.1:
version "3.0.1"
resolved "https://registry.yarnpkg.com/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz#6336e8d71965cb3d35a1bbb7868445a7c05264bf"
integrity sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==

v8-compile-cache@^2.0.2, v8-compile-cache@^2.0.3:
version "2.0.3"
Expand Down