From 8c98b653945d5c26199d8a5f499ee10034895ede Mon Sep 17 00:00:00 2001 From: chris Date: Tue, 12 Sep 2023 16:49:01 -0700 Subject: [PATCH] engage typescript conditions when typescript parent path is detected --- tests/tests-basic/package.json | 12 +++++++++--- .../{workspaces/a => workspaces-js/js-a}/index.js | 0 .../a => workspaces-js/js-a}/package.json | 2 +- .../{workspaces/b => workspaces-js/js-b}/index.js | 0 .../b => workspaces-js/js-b}/package.json | 4 ++-- .../{workspaces/b => workspaces-js/js-b}/test.js | 4 ++-- tests/tests-basic/workspaces-ts/ts-a/index.ts | 3 +++ tests/tests-basic/workspaces-ts/ts-a/package.json | 6 ++++++ tests/tests-basic/workspaces-ts/ts-b/index.ts | 5 +++++ tests/tests-basic/workspaces-ts/ts-b/package.json | 14 ++++++++++++++ tests/tests-basic/workspaces-ts/ts-b/test.ts | 12 ++++++++++++ tests/tests-basic/workspaces-ts/ts-b/tsconfig.json | 8 ++++++++ 12 files changed, 62 insertions(+), 8 deletions(-) rename tests/tests-basic/{workspaces/a => workspaces-js/js-a}/index.js (100%) rename tests/tests-basic/{workspaces/a => workspaces-js/js-a}/package.json (78%) rename tests/tests-basic/{workspaces/b => workspaces-js/js-b}/index.js (100%) rename tests/tests-basic/{workspaces/b => workspaces-js/js-b}/package.json (79%) rename tests/tests-basic/{workspaces/b => workspaces-js/js-b}/test.js (76%) create mode 100644 tests/tests-basic/workspaces-ts/ts-a/index.ts create mode 100644 tests/tests-basic/workspaces-ts/ts-a/package.json create mode 100644 tests/tests-basic/workspaces-ts/ts-b/index.ts create mode 100644 tests/tests-basic/workspaces-ts/ts-b/package.json create mode 100644 tests/tests-basic/workspaces-ts/ts-b/test.ts create mode 100644 tests/tests-basic/workspaces-ts/ts-b/tsconfig.json diff --git a/tests/tests-basic/package.json b/tests/tests-basic/package.json index e78fc31..31b5056 100644 --- a/tests/tests-basic/package.json +++ b/tests/tests-basic/package.json @@ -20,9 +20,15 @@ "nodejsexample_12_exports": "file:nodejsexample_12_exports", "resolvewithplus": "file:.." }, - "workspaces": ["workspaces/*"], + "workspaces": [ + "workspaces-js/*", + "workspaces-ts/*" + ], "scripts": { - "test-workspace": "npm --prefix workspaces/b test", - "test": "node --experimental-import-meta-resolve --test tests-basic.test.js tests-export-patterns.test.js tests-import-patterns.test.js" + "test-workspaces-js": "npm --prefix workspaces-js/js-b test", + "test-workspaces-ts": "npm --prefix workspaces-ts/ts-b test", + "test-workspaces": "npm run test-workspaces-js && npm run test-workspaces-ts", + "test-vanilla": "node --experimental-import-meta-resolve --test tests-basic.test.js tests-export-patterns.test.js tests-import-patterns.test.js", + "test": "npm run test-workspaces && npm run test-vanilla" } } diff --git a/tests/tests-basic/workspaces/a/index.js b/tests/tests-basic/workspaces-js/js-a/index.js similarity index 100% rename from tests/tests-basic/workspaces/a/index.js rename to tests/tests-basic/workspaces-js/js-a/index.js diff --git a/tests/tests-basic/workspaces/a/package.json b/tests/tests-basic/workspaces-js/js-a/package.json similarity index 78% rename from tests/tests-basic/workspaces/a/package.json rename to tests/tests-basic/workspaces-js/js-a/package.json index e9ec9a1..17e9f94 100644 --- a/tests/tests-basic/workspaces/a/package.json +++ b/tests/tests-basic/workspaces-js/js-a/package.json @@ -1,5 +1,5 @@ { - "name": "a", + "name": "js-a", "version": "0.0.0", "type": "module", "main": "index.js" diff --git a/tests/tests-basic/workspaces/b/index.js b/tests/tests-basic/workspaces-js/js-b/index.js similarity index 100% rename from tests/tests-basic/workspaces/b/index.js rename to tests/tests-basic/workspaces-js/js-b/index.js diff --git a/tests/tests-basic/workspaces/b/package.json b/tests/tests-basic/workspaces-js/js-b/package.json similarity index 79% rename from tests/tests-basic/workspaces/b/package.json rename to tests/tests-basic/workspaces-js/js-b/package.json index 0b16570..835a4db 100644 --- a/tests/tests-basic/workspaces/b/package.json +++ b/tests/tests-basic/workspaces-js/js-b/package.json @@ -1,11 +1,11 @@ { - "name": "b", + "name": "js-b", "version": "0.0.0", "type": "module", "scripts": { "test": "node --experimental-import-meta-resolve --test" }, "dependencies": { - "a": "^0.0.0" + "js-a": "^0.0.0" } } diff --git a/tests/tests-basic/workspaces/b/test.js b/tests/tests-basic/workspaces-js/js-b/test.js similarity index 76% rename from tests/tests-basic/workspaces/b/test.js rename to tests/tests-basic/workspaces-js/js-b/test.js index 325b30b..e30f2f9 100644 --- a/tests/tests-basic/workspaces/b/test.js +++ b/tests/tests-basic/workspaces-js/js-b/test.js @@ -4,6 +4,6 @@ import resolvewithplus from '../../../../resolvewithplus.js' test('should return workspace paths', () => { assert.strictEqual( - import.meta.resolve('a'), - resolvewithplus('a')) + import.meta.resolve('js-a'), + resolvewithplus('js-a')) }) diff --git a/tests/tests-basic/workspaces-ts/ts-a/index.ts b/tests/tests-basic/workspaces-ts/ts-a/index.ts new file mode 100644 index 0000000..c970c82 --- /dev/null +++ b/tests/tests-basic/workspaces-ts/ts-a/index.ts @@ -0,0 +1,3 @@ +export function foo () { + return 'foo' +} diff --git a/tests/tests-basic/workspaces-ts/ts-a/package.json b/tests/tests-basic/workspaces-ts/ts-a/package.json new file mode 100644 index 0000000..b197b2f --- /dev/null +++ b/tests/tests-basic/workspaces-ts/ts-a/package.json @@ -0,0 +1,6 @@ +{ + "name": "ts-a", + "version": "0.0.0", + "type": "module", + "main": "index.js" +} diff --git a/tests/tests-basic/workspaces-ts/ts-b/index.ts b/tests/tests-basic/workspaces-ts/ts-b/index.ts new file mode 100644 index 0000000..cd0f9ec --- /dev/null +++ b/tests/tests-basic/workspaces-ts/ts-b/index.ts @@ -0,0 +1,5 @@ +import {foo} from 'a' + +export default function test () { + return foo() +} diff --git a/tests/tests-basic/workspaces-ts/ts-b/package.json b/tests/tests-basic/workspaces-ts/ts-b/package.json new file mode 100644 index 0000000..0ba0065 --- /dev/null +++ b/tests/tests-basic/workspaces-ts/ts-b/package.json @@ -0,0 +1,14 @@ +{ + "name": "ts-b", + "version": "0.0.0", + "type": "module", + "scripts": { + "test": "node --loader=ts-node/esm --test test.ts" + }, + "dependencies": { + "ts-a": "^0.0.0" + }, + "devDependencies": { + "ts-node": "^10.9.1" + } +} diff --git a/tests/tests-basic/workspaces-ts/ts-b/test.ts b/tests/tests-basic/workspaces-ts/ts-b/test.ts new file mode 100644 index 0000000..509b072 --- /dev/null +++ b/tests/tests-basic/workspaces-ts/ts-b/test.ts @@ -0,0 +1,12 @@ +import test from 'node:test' +import assert from 'node:assert/strict' +import resolvewithplus from '../../../../resolvewithplus.js' + +console.log('test here!') +/* +test('should return workspace paths', () => { + assert.strictEqual( + import.meta.resolve('ts-a'), + resolvewithplus('ts-a')) +}) +*/ diff --git a/tests/tests-basic/workspaces-ts/ts-b/tsconfig.json b/tests/tests-basic/workspaces-ts/ts-b/tsconfig.json new file mode 100644 index 0000000..5b17f4e --- /dev/null +++ b/tests/tests-basic/workspaces-ts/ts-b/tsconfig.json @@ -0,0 +1,8 @@ +{ + "esm": true, + "compilerOptions": { + "allowSyntheticDefaultImports": true, + "module": "ESNext", + "moduleResolution": "node" + } +}