diff options
| author | David Sherret <dsherret@users.noreply.github.com> | 2024-07-03 20:54:33 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-04 00:54:33 +0000 |
| commit | 147411e64b22fe74cb258125acab83f9182c9f81 (patch) | |
| tree | a1f63dcbf0404c20534986b10f02b649df5a3ad5 /tests/specs/npm | |
| parent | dd6d19e12051fac2ea5639f621501f4710a1b8e1 (diff) | |
feat: npm workspace and better Deno workspace support (#24334)
Adds much better support for the unstable Deno workspaces as well as
support for npm workspaces. npm workspaces is still lacking in that we
only install packages into the root node_modules folder. We'll make it
smarter over time in order for it to figure out when to add node_modules
folders within packages.
This includes a breaking change in config file resolution where we stop
searching for config files on the first found package.json unless it's
in a workspace. For the previous behaviour, the root deno.json needs to
be updated to be a workspace by adding `"workspace":
["./path-to-pkg-json-folder-goes-here"]`. See details in
https://github.com/denoland/deno_config/pull/66
Closes #24340
Closes #24159
Closes #24161
Closes #22020
Closes #18546
Closes #16106
Closes #24160
Diffstat (limited to 'tests/specs/npm')
28 files changed, 192 insertions, 26 deletions
diff --git a/tests/specs/npm/check_prefers_non_types_node_pkg/__test__.jsonc b/tests/specs/npm/check_prefers_non_types_node_pkg/__test__.jsonc index ed3827ef6..8c4d0fb20 100644 --- a/tests/specs/npm/check_prefers_non_types_node_pkg/__test__.jsonc +++ b/tests/specs/npm/check_prefers_non_types_node_pkg/__test__.jsonc @@ -1,7 +1,28 @@ { - "envs": { - "DENO_FUTURE": "1" - }, - "args": "check --quiet main.ts", - "output": "" + "tempDir": true, + "tests": { + "byonm": { + "envs": { + "DENO_FUTURE": "1" + }, + "steps": [{ + "args": "install", + "output": "[WILDCARD]" + }, { + "args": "check --quiet main.ts", + "exitCode": 1, + "output": "expected.out" + }] + }, + "auto_install": { + "args": "check --node-modules-dir=true --quiet main.ts", + "exitCode": 1, + "output": "expected.out" + }, + "global_folder": { + "args": "check --node-modules-dir=false --quiet main.ts", + "exitCode": 1, + "output": "expected.out" + } + } } diff --git a/tests/specs/npm/check_prefers_non_types_node_pkg/expected.out b/tests/specs/npm/check_prefers_non_types_node_pkg/expected.out new file mode 100644 index 000000000..37d41aae2 --- /dev/null +++ b/tests/specs/npm/check_prefers_non_types_node_pkg/expected.out @@ -0,0 +1,4 @@ +error: TS2345 [ERROR]: Argument of type 'number' is not assignable to parameter of type 'string'. +console.log(compressToEncodedURIComponent(123)); + ~~~ + at file:///[WILDLINE] diff --git a/tests/specs/npm/check_prefers_non_types_node_pkg/main.ts b/tests/specs/npm/check_prefers_non_types_node_pkg/main.ts index 8774bdbfc..f28d132d1 100644 --- a/tests/specs/npm/check_prefers_non_types_node_pkg/main.ts +++ b/tests/specs/npm/check_prefers_non_types_node_pkg/main.ts @@ -1,3 +1,5 @@ +// this lz-string@1.5 pkg has types only in the regular package and not the @types/lz-string pkg import { compressToEncodedURIComponent } from "lz-string"; -console.log(compressToEncodedURIComponent("Hello, World!")); +// cause a deliberate type checking error +console.log(compressToEncodedURIComponent(123)); diff --git a/tests/specs/npm/check_prefers_non_types_node_pkg/node_modules/@types/lz-string/package.json b/tests/specs/npm/check_prefers_non_types_node_pkg/node_modules/@types/lz-string/package.json deleted file mode 100644 index afe623e00..000000000 --- a/tests/specs/npm/check_prefers_non_types_node_pkg/node_modules/@types/lz-string/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "@types/lz-string", - "version": "1.5.0", - "description": "Stub TypeScript definitions entry for lz-string, which provides its own types definitions", - "main": "", - "scripts": {}, - "license": "MIT", - "dependencies": { - "lz-string": "*" - }, - "deprecated": "This is a stub types definition. lz-string provides its own type definitions, so you do not need this installed." -} diff --git a/tests/specs/npm/check_prefers_non_types_node_pkg/node_modules/lz-string/index.d.ts b/tests/specs/npm/check_prefers_non_types_node_pkg/node_modules/lz-string/index.d.ts deleted file mode 100644 index b6abfd8ba..000000000 --- a/tests/specs/npm/check_prefers_non_types_node_pkg/node_modules/lz-string/index.d.ts +++ /dev/null @@ -1 +0,0 @@ -export function compressToEncodedURIComponent(input: string): string; diff --git a/tests/specs/npm/check_prefers_non_types_node_pkg/node_modules/lz-string/index.js b/tests/specs/npm/check_prefers_non_types_node_pkg/node_modules/lz-string/index.js deleted file mode 100644 index 603b710ba..000000000 --- a/tests/specs/npm/check_prefers_non_types_node_pkg/node_modules/lz-string/index.js +++ /dev/null @@ -1 +0,0 @@ -module.exports.compressToEncodedURIComponent = (a) => a; diff --git a/tests/specs/npm/check_prefers_non_types_node_pkg/node_modules/lz-string/package.json b/tests/specs/npm/check_prefers_non_types_node_pkg/node_modules/lz-string/package.json deleted file mode 100644 index f8bfd5d98..000000000 --- a/tests/specs/npm/check_prefers_non_types_node_pkg/node_modules/lz-string/package.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "name": "lz-string", - "version": "1.5.0" -}
\ No newline at end of file diff --git a/tests/specs/npm/check_prefers_non_types_node_pkg/package.json b/tests/specs/npm/check_prefers_non_types_node_pkg/package.json index ea3b2d26f..a812a973e 100644 --- a/tests/specs/npm/check_prefers_non_types_node_pkg/package.json +++ b/tests/specs/npm/check_prefers_non_types_node_pkg/package.json @@ -1,6 +1,6 @@ { "dependencies": { - "lz-string": "*", - "@types/lz-string": "*" + "lz-string": "1.5", + "@types/lz-string": "1.5" } } diff --git a/tests/specs/npm/check_types_in_types_pkg/__test__.jsonc b/tests/specs/npm/check_types_in_types_pkg/__test__.jsonc new file mode 100644 index 000000000..7b7a429f4 --- /dev/null +++ b/tests/specs/npm/check_types_in_types_pkg/__test__.jsonc @@ -0,0 +1,28 @@ +{ + "tempDir": true, + "tests": { + "byonm": { + "envs": { + "DENO_FUTURE": "1" + }, + "steps": [{ + "args": "install", + "output": "[WILDCARD]" + }, { + "args": "check --quiet main.ts", + "exitCode": 1, + "output": "expected.out" + }] + }, + "auto_install": { + "args": "check --node-modules-dir=true --quiet main_auto_install.ts", + "exitCode": 1, + "output": "expected.out" + }, + "global_folder": { + "args": "check --node-modules-dir=false --quiet main_auto_install.ts", + "exitCode": 1, + "output": "expected.out" + } + } +} diff --git a/tests/specs/npm/check_types_in_types_pkg/expected.out b/tests/specs/npm/check_types_in_types_pkg/expected.out new file mode 100644 index 000000000..37d41aae2 --- /dev/null +++ b/tests/specs/npm/check_types_in_types_pkg/expected.out @@ -0,0 +1,4 @@ +error: TS2345 [ERROR]: Argument of type 'number' is not assignable to parameter of type 'string'. +console.log(compressToEncodedURIComponent(123)); + ~~~ + at file:///[WILDLINE] diff --git a/tests/specs/npm/check_types_in_types_pkg/main.ts b/tests/specs/npm/check_types_in_types_pkg/main.ts new file mode 100644 index 000000000..adc164ea5 --- /dev/null +++ b/tests/specs/npm/check_types_in_types_pkg/main.ts @@ -0,0 +1,5 @@ +// this lz-string@1.3 pkg doesn't have types, but the @types/lz-string@1.3 does +import { compressToEncodedURIComponent } from "lz-string"; + +// cause a deliberate type checking error +console.log(compressToEncodedURIComponent(123)); diff --git a/tests/specs/npm/check_types_in_types_pkg/main_auto_install.ts b/tests/specs/npm/check_types_in_types_pkg/main_auto_install.ts new file mode 100644 index 000000000..af47e13ac --- /dev/null +++ b/tests/specs/npm/check_types_in_types_pkg/main_auto_install.ts @@ -0,0 +1,6 @@ +// this lz-string@1.3 pkg doesn't have types, but the @types/lz-string@1.3 does +// @deno-types="@types/lz-string" +import { compressToEncodedURIComponent } from "lz-string"; + +// cause a deliberate type checking error +console.log(compressToEncodedURIComponent(123)); diff --git a/tests/specs/npm/check_types_in_types_pkg/package.json b/tests/specs/npm/check_types_in_types_pkg/package.json new file mode 100644 index 000000000..e8079d112 --- /dev/null +++ b/tests/specs/npm/check_types_in_types_pkg/package.json @@ -0,0 +1,6 @@ +{ + "dependencies": { + "lz-string": "1.3", + "@types/lz-string": "1.3" + } +} diff --git a/tests/specs/npm/workspace_basic/__test__.jsonc b/tests/specs/npm/workspace_basic/__test__.jsonc new file mode 100644 index 000000000..79e059ca1 --- /dev/null +++ b/tests/specs/npm/workspace_basic/__test__.jsonc @@ -0,0 +1,35 @@ +{ + "tempDir": true, + "tests": { + "global_cache": { + "args": "run --node-modules-dir=false b/main.ts", + "output": "b/main_global_cache.out" + }, + "node_modules_dir": { + "args": "run --node-modules-dir=true b/main.ts", + "output": "b/main_node_modules_dir.out" + }, + "byonm": { + "envs": { + "DENO_FUTURE": "1" + }, + "steps": [{ + "args": "install", + "output": "[WILDCARD]" + }, { + "args": "run b/main.ts", + "output": "b/main_byonm.out" + }] + }, + "exports_sub_path_not_exists": { + "args": "run b/exports-sub-path-not-exists.ts", + "output": "b/exports-sub-path-not-exists.out", + "exitCode": 1 + }, + "no_exports_sub_path_not_exists": { + "args": "run b/no-exports-sub-path-not-exists.ts", + "output": "b/no-exports-sub-path-not-exists.out", + "exitCode": 1 + } + } +} diff --git a/tests/specs/npm/workspace_basic/a/mod.ts b/tests/specs/npm/workspace_basic/a/mod.ts new file mode 100644 index 000000000..9f8d1c594 --- /dev/null +++ b/tests/specs/npm/workspace_basic/a/mod.ts @@ -0,0 +1,6 @@ +import { getValue, setValue } from "@denotest/esm-basic"; + +export function sayHello() { + setValue(5); + console.log("Hello", getValue()); +} diff --git a/tests/specs/npm/workspace_basic/a/package.json b/tests/specs/npm/workspace_basic/a/package.json new file mode 100644 index 000000000..1467823cf --- /dev/null +++ b/tests/specs/npm/workspace_basic/a/package.json @@ -0,0 +1,10 @@ +{ + "name": "@denotest/a", + "version": "1.0.0", + "dependencies": { + "@denotest/esm-basic": "*" + }, + "exports": { + ".": "./mod.ts" + } +} diff --git a/tests/specs/npm/workspace_basic/b/exports-sub-path-not-exists.out b/tests/specs/npm/workspace_basic/b/exports-sub-path-not-exists.out new file mode 100644 index 000000000..5e61cdfc3 --- /dev/null +++ b/tests/specs/npm/workspace_basic/b/exports-sub-path-not-exists.out @@ -0,0 +1,2 @@ +error: [ERR_PACKAGE_PATH_NOT_EXPORTED] Package subpath './non-existent' is not defined by "exports" in '[WILDLINE]package.json' imported from '[WILDLINE]exports-sub-path-not-exists.ts' + at file:///[WILDLINE]exports-sub-path-not-exists.ts:1:20 diff --git a/tests/specs/npm/workspace_basic/b/exports-sub-path-not-exists.ts b/tests/specs/npm/workspace_basic/b/exports-sub-path-not-exists.ts new file mode 100644 index 000000000..716f0f97d --- /dev/null +++ b/tests/specs/npm/workspace_basic/b/exports-sub-path-not-exists.ts @@ -0,0 +1,2 @@ +import * as a from "@denotest/a/non-existent"; +console.log(a); diff --git a/tests/specs/npm/workspace_basic/b/main.ts b/tests/specs/npm/workspace_basic/b/main.ts new file mode 100644 index 000000000..03956388c --- /dev/null +++ b/tests/specs/npm/workspace_basic/b/main.ts @@ -0,0 +1,9 @@ +import * as a1 from "@denotest/a"; +import * as a2 from "npm:@denotest/a@1"; +import * as a3 from "npm:@denotest/a@workspace"; +import * as c from "@denotest/c"; + +a1.sayHello(); +a2.sayHello(); +a3.sayHello(); +c.sayHello(); diff --git a/tests/specs/npm/workspace_basic/b/main_byonm.out b/tests/specs/npm/workspace_basic/b/main_byonm.out new file mode 100644 index 000000000..3a311dcd7 --- /dev/null +++ b/tests/specs/npm/workspace_basic/b/main_byonm.out @@ -0,0 +1,4 @@ +Hello 5 +Hello 5 +Hello 5 +C: Hi! diff --git a/tests/specs/npm/workspace_basic/b/main_global_cache.out b/tests/specs/npm/workspace_basic/b/main_global_cache.out new file mode 100644 index 000000000..1ca11026a --- /dev/null +++ b/tests/specs/npm/workspace_basic/b/main_global_cache.out @@ -0,0 +1,6 @@ +Download http://localhost:4260/@denotest/esm-basic +Download http://localhost:4260/@denotest/esm-basic/1.0.0.tgz +Hello 5 +Hello 5 +Hello 5 +C: Hi! diff --git a/tests/specs/npm/workspace_basic/b/main_node_modules_dir.out b/tests/specs/npm/workspace_basic/b/main_node_modules_dir.out new file mode 100644 index 000000000..82a49b9fe --- /dev/null +++ b/tests/specs/npm/workspace_basic/b/main_node_modules_dir.out @@ -0,0 +1,7 @@ +Download http://localhost:4260/@denotest/esm-basic +Download http://localhost:4260/@denotest/esm-basic/1.0.0.tgz +Initialize @denotest/esm-basic@1.0.0 +Hello 5 +Hello 5 +Hello 5 +C: Hi! diff --git a/tests/specs/npm/workspace_basic/b/no-exports-sub-path-not-exists.out b/tests/specs/npm/workspace_basic/b/no-exports-sub-path-not-exists.out new file mode 100644 index 000000000..f98aa34cb --- /dev/null +++ b/tests/specs/npm/workspace_basic/b/no-exports-sub-path-not-exists.out @@ -0,0 +1,3 @@ +[# not the best error, but it did resolve because there was no exports specified] +error: Module not found "file:///[WILDLINE]/c/non-existent". + at file:///[WILDLINE]/b/no-exports-sub-path-not-exists.ts:1:20 diff --git a/tests/specs/npm/workspace_basic/b/no-exports-sub-path-not-exists.ts b/tests/specs/npm/workspace_basic/b/no-exports-sub-path-not-exists.ts new file mode 100644 index 000000000..960d32870 --- /dev/null +++ b/tests/specs/npm/workspace_basic/b/no-exports-sub-path-not-exists.ts @@ -0,0 +1,2 @@ +import * as c from "@denotest/c/non-existent"; +console.log(c); diff --git a/tests/specs/npm/workspace_basic/b/package.json b/tests/specs/npm/workspace_basic/b/package.json new file mode 100644 index 000000000..4b876d5b9 --- /dev/null +++ b/tests/specs/npm/workspace_basic/b/package.json @@ -0,0 +1,8 @@ +{ + "name": "@denotest/b", + "version": "1.0.0", + "dependencies": { + "@denotest/a": "1", + "@denotest/c": "workspace:*" + } +} diff --git a/tests/specs/npm/workspace_basic/c/index.js b/tests/specs/npm/workspace_basic/c/index.js new file mode 100644 index 000000000..f412f7d4b --- /dev/null +++ b/tests/specs/npm/workspace_basic/c/index.js @@ -0,0 +1,3 @@ +export function sayHello() { + console.log("C: Hi!"); +} diff --git a/tests/specs/npm/workspace_basic/c/package.json b/tests/specs/npm/workspace_basic/c/package.json new file mode 100644 index 000000000..7d5ca9abf --- /dev/null +++ b/tests/specs/npm/workspace_basic/c/package.json @@ -0,0 +1,4 @@ +{ + "name": "@denotest/c", + "version": "1.0.0" +} diff --git a/tests/specs/npm/workspace_basic/package.json b/tests/specs/npm/workspace_basic/package.json new file mode 100644 index 000000000..e3dd981e5 --- /dev/null +++ b/tests/specs/npm/workspace_basic/package.json @@ -0,0 +1,7 @@ +{ + "workspaces": [ + "./a", + "./b", + "./c" + ] +} |
