From 07d4644f2367df9c9ae7704bcf14b24198e81885 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Thu, 30 May 2024 09:00:08 -0300 Subject: [PATCH 01/10] feat: introduces typings --- .gitignore | 1 + index.d.ts | 3 ++ lib/canRegisterLoader.d.ts | 1 + lib/esm-import-functions.d.ts | 7 ++++ lib/quibble-registered.d.mts | 5 +++ lib/quibble.d.mts | 66 ++++++++++++++++++++++++++++++++ lib/quibble.d.ts | 24 ++++++++++++ lib/thisWillRunInUserThread.d.ts | 42 ++++++++++++++++++++ package-lock.json | 33 ++++++++++++++++ package.json | 1 + 10 files changed, 183 insertions(+) create mode 100644 index.d.ts create mode 100644 lib/canRegisterLoader.d.ts create mode 100644 lib/esm-import-functions.d.ts create mode 100644 lib/quibble-registered.d.mts create mode 100644 lib/quibble.d.mts create mode 100644 lib/quibble.d.ts create mode 100644 lib/thisWillRunInUserThread.d.ts diff --git a/.gitignore b/.gitignore index 96978ba..bd3452d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ npm-debug.log* #ignore node_modules, as the node project is not "deployed" per se: http://www.mikealrogers.com/posts/nodemodules-in-git.html /node_modules +.DS_Store diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..8154792 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,3 @@ +import quibble from './lib/quibble'; + +export { quibble as default }; diff --git a/lib/canRegisterLoader.d.ts b/lib/canRegisterLoader.d.ts new file mode 100644 index 0000000..035dade --- /dev/null +++ b/lib/canRegisterLoader.d.ts @@ -0,0 +1 @@ +export declare function canRegisterLoader(): boolean; diff --git a/lib/esm-import-functions.d.ts b/lib/esm-import-functions.d.ts new file mode 100644 index 0000000..25ff86c --- /dev/null +++ b/lib/esm-import-functions.d.ts @@ -0,0 +1,7 @@ +export declare function dummyImportModuleToGetAtPath( + modulePath: string +): Promise; + +export declare function importOriginalModule( + fullImportPath: string +): Promise; diff --git a/lib/quibble-registered.d.mts b/lib/quibble-registered.d.mts new file mode 100644 index 0000000..caf6e5e --- /dev/null +++ b/lib/quibble-registered.d.mts @@ -0,0 +1,5 @@ +import { GlobalPreloadOptions } from './quibble.mjs'; + +export * from './quibble.mjs'; + +export declare function initialize({ port }: GlobalPreloadOptions): void; diff --git a/lib/quibble.d.mts b/lib/quibble.d.mts new file mode 100644 index 0000000..b13b4ce --- /dev/null +++ b/lib/quibble.d.mts @@ -0,0 +1,66 @@ +/// + +import { MessagePort } from 'node:worker_threads'; +import quibble from './quibble.js'; + +export default quibble; + +export declare const reset: any; + +export declare const ignoreCallsFromThisFile: any; + +export declare const config: any; + +export declare const isLoaderLoaded: any; + +export type ModuleLoaderMockInfo = { + hasDefaultExportStub: boolean; + namedExports: string[]; +}; + +export type ResolveContext = { + parentURL?: string; +}; + +export type ResolveFunction = ( + specifier: string, + context: ResolveContext, + nextResolve: ( + specifier: string, + context: ResolveContext + ) => Promise<{ + url: string; + }> +) => Promise<{ + url: string; +}>; + +export type LoadContext = { + format: string; +}; + +export type LoadFunction = ( + url: string, + context: LoadContext, + nextLoad: ( + url: string, + context: LoadContext + ) => Promise<{ + source: string | SharedArrayBuffer | Uint8Array; + format: string; + }> +) => Promise<{ + source: string | SharedArrayBuffer | Uint8Array; + format: string; + shortCircuit?: boolean; +}>; + +export type GlobalPreloadOptions = { + port: MessagePort; +}; + +export declare const resolve: ResolveFunction; + +export declare const load: LoadFunction; + +export declare const globalPreload: ({ port }: GlobalPreloadOptions) => string; diff --git a/lib/quibble.d.ts b/lib/quibble.d.ts new file mode 100644 index 0000000..84d0f6b --- /dev/null +++ b/lib/quibble.d.ts @@ -0,0 +1,24 @@ +type QuibbleConfig = { + defaultFakeCreator: (request: string) => any; +}; + +declare const quibble: ((request: string, stub?: any) => any) & { + config(userConfig: Partial): QuibbleConfig; + ignoreCallsFromThisFile(file?: string): void; + reset(hard?: boolean): void; + absolutify(relativePath: string, parentFileName?: string): string; + esm( + specifier: string, + namedExportStubs?: Record, + defaultExportStub?: any + ): Promise; + listMockedModules(): string[]; + isLoaderLoaded(): boolean; + esmImportWithPath(specifier: string): Promise<{ + modulePath: string; + moduleUrl: string; + module: any; + }>; +}; + +export default quibble; diff --git a/lib/thisWillRunInUserThread.d.ts b/lib/thisWillRunInUserThread.d.ts new file mode 100644 index 0000000..357882e --- /dev/null +++ b/lib/thisWillRunInUserThread.d.ts @@ -0,0 +1,42 @@ +/// + +import { MessagePort } from 'node:worker_threads'; + +export type ResetFunction = () => void; + +export type AddMockedModuleFunction = ( + moduleUrl: string, + options: { + namedExportStubs: Record; + defaultExportStub: any; + } +) => void; + +export type ListMockedModulesFunction = () => string[]; + +export type UserToLoaderCommunication = { + reset: ResetFunction; + addMockedModule: AddMockedModuleFunction; + listMockedModules: ListMockedModulesFunction; +}; + +export type QuibbleUserState = { + quibbledModules: Map; +}; + +export type QuibbleLoaderState = { + quibbledModules: Map; + stubModuleGeneration: number; +}; + +export type GlobalThis = typeof globalThis & { + [key: symbol]: + | QuibbleUserState + | UserToLoaderCommunication + | QuibbleLoaderState; +}; + +export declare const thisWillRunInUserThread: ( + globalThis: GlobalThis, + port: MessagePort +) => void; diff --git a/package-lock.json b/package-lock.json index e9baa95..1f08181 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "resolve": "^1.22.8" }, "devDependencies": { + "@types/node": "^20.12.13", "core-assert": "^1.0.0", "is-number": "^7.0.0", "is-promise": "^4.0.0", @@ -163,6 +164,16 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, + "node_modules/@types/node": { + "version": "20.12.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.13.tgz", + "integrity": "sha512-gBGeanV41c1L171rR7wjbMiEpEI/l5XFQdLLfhr/REwpgDy/4U8y89+i8kRiLzDyZdOkXh+cRaTetUnCYutoXA==", + "dev": true, + "license": "MIT", + "dependencies": { + "undici-types": "~5.26.4" + } + }, "node_modules/acorn": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz", @@ -2954,6 +2965,13 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true, + "license": "MIT" + }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -3156,6 +3174,15 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, + "@types/node": { + "version": "20.12.13", + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.13.tgz", + "integrity": "sha512-gBGeanV41c1L171rR7wjbMiEpEI/l5XFQdLLfhr/REwpgDy/4U8y89+i8kRiLzDyZdOkXh+cRaTetUnCYutoXA==", + "dev": true, + "requires": { + "undici-types": "~5.26.4" + } + }, "acorn": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz", @@ -5160,6 +5187,12 @@ "which-boxed-primitive": "^1.0.2" } }, + "undici-types": { + "version": "5.26.5", + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", + "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", + "dev": true + }, "uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", diff --git a/package.json b/package.json index 5aa8af4..3c8e691 100644 --- a/package.json +++ b/package.json @@ -35,6 +35,7 @@ "resolve": "^1.22.8" }, "devDependencies": { + "@types/node": "^20.12.13", "core-assert": "^1.0.0", "is-number": "^7.0.0", "is-promise": "^4.0.0", From b92f826b09a00d31f9dad29267cbfc82e48b7cf9 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Thu, 30 May 2024 09:07:15 -0300 Subject: [PATCH 02/10] ci: add build tests for typings --- .github/workflows/typings.yml | 30 ++++++++++++++++++++++++++++++ package-lock.json | 23 ++++++++++++++++++++++- package.json | 4 +++- tsconfig.json | 7 +++++++ 4 files changed, 62 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/typings.yml create mode 100644 tsconfig.json diff --git a/.github/workflows/typings.yml b/.github/workflows/typings.yml new file mode 100644 index 0000000..6a78abe --- /dev/null +++ b/.github/workflows/typings.yml @@ -0,0 +1,30 @@ +# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node +# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions + +name: Typings CI + +on: + push: + branches: [ "main" ] + pull_request: + branches: [ "main" ] + +jobs: + build: + + strategy: + matrix: + node-version: [20.x] + os: [ubuntu-latest] + + runs-on: ${{ matrix.os }} + + steps: + - uses: actions/checkout@v3 + - name: Use Node.js ${{ matrix.node-version }} + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + cache: 'npm' + - run: npm ci + - run: npm run test:typings diff --git a/package-lock.json b/package-lock.json index 1f08181..c7a8b00 100644 --- a/package-lock.json +++ b/package-lock.json @@ -19,7 +19,8 @@ "is-promise": "^4.0.0", "standard": "^17.1.0", "teenytest": "^6.0.5", - "teenytest-promise": "^1.0.0" + "teenytest-promise": "^1.0.0", + "typescript": "^5.4.5" }, "engines": { "node": ">= 0.14.0" @@ -2950,6 +2951,20 @@ "url": "https://github.com/sponsors/ljharb" } }, + "node_modules/typescript": { + "version": "5.4.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", + "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "dev": true, + "license": "Apache-2.0", + "bin": { + "tsc": "bin/tsc", + "tsserver": "bin/tsserver" + }, + "engines": { + "node": ">=14.17" + } + }, "node_modules/unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -5175,6 +5190,12 @@ "is-typed-array": "^1.1.9" } }, + "typescript": { + "version": "5.4.5", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", + "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", + "dev": true + }, "unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", diff --git a/package.json b/package.json index 3c8e691..2a2ca93 100644 --- a/package.json +++ b/package.json @@ -22,6 +22,7 @@ "test:example-esm-auto-loader": "node test/esm-lib/supports-auto-load.js not || (cd example-esm && npm i && npm run test-auto-loader)", "test:smells": "bash ./test/require-smell-test.sh", "test:ci": "npm test && npm run test:esm && npm run test:no-loader-esm && npm run test:esm-auto-loader && npm run style && npm run test:example && npm run test:example-esm && npm run test:example-esm-auto-loader && npm run test:smells", + "test:typings": "tsc", "preversion": "git pull --rebase && npm run test:ci", "postversion": "git push && git push --tags && npm publish" }, @@ -41,7 +42,8 @@ "is-promise": "^4.0.0", "standard": "^17.1.0", "teenytest": "^6.0.5", - "teenytest-promise": "^1.0.0" + "teenytest-promise": "^1.0.0", + "typescript": "^5.4.5" }, "standard": { "globals": [ diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..26b4e93 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,7 @@ +{ + "compilerOptions": { + "noEmit": true, + "skipLibCheck": false, + }, + "include": ["lib/**/*.d.ts"] +} From e777d2053f9bce6081978f621033ef9aba8c7905 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Thu, 30 May 2024 09:33:34 -0300 Subject: [PATCH 03/10] chore: simplify default exports --- index.d.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 8154792..173726a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,3 +1 @@ -import quibble from './lib/quibble'; - -export { quibble as default }; +export * from './lib/quibble.js'; From 7fbbc470a9aeb325bc0415a85752ed0562c3a72d Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Thu, 30 May 2024 10:17:26 -0300 Subject: [PATCH 04/10] ci: stricter typings tests --- index.d.ts | 4 +++- tsconfig.json | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/index.d.ts b/index.d.ts index 173726a..669ef87 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1 +1,3 @@ -export * from './lib/quibble.js'; +import quibble from './lib/quibble.js'; + +export default quibble; diff --git a/tsconfig.json b/tsconfig.json index 26b4e93..64f130f 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,7 +1,15 @@ { + "include": ["lib/**/*.d.ts"], "compilerOptions": { - "noEmit": true, + "forceConsistentCasingInFileNames": true, + "isolatedModules": true, + "strict": true, + "alwaysStrict": true, + "strictFunctionTypes": true, + "noUnusedLocals": true, + "noImplicitAny": true, + "esModuleInterop": true, "skipLibCheck": false, - }, - "include": ["lib/**/*.d.ts"] + "noEmit": true, + } } From 83ccf6b192aafa2e00b9fd17ff3af13dca757765 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Thu, 30 May 2024 10:18:51 -0300 Subject: [PATCH 05/10] ci: include index.d.ts --- tsconfig.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tsconfig.json b/tsconfig.json index 64f130f..e930e76 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,5 +1,5 @@ { - "include": ["lib/**/*.d.ts"], + "include": ["index.d.ts", "lib/**/*.d.ts"], "compilerOptions": { "forceConsistentCasingInFileNames": true, "isolatedModules": true, From 7755a546af762f502d025b7efa7c8c2842aa127a Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Fri, 31 May 2024 09:57:38 -0300 Subject: [PATCH 06/10] ci: remove typings build tests --- .github/workflows/typings.yml | 30 ------------------- package-lock.json | 56 +---------------------------------- package.json | 4 +-- 3 files changed, 2 insertions(+), 88 deletions(-) delete mode 100644 .github/workflows/typings.yml diff --git a/.github/workflows/typings.yml b/.github/workflows/typings.yml deleted file mode 100644 index 6a78abe..0000000 --- a/.github/workflows/typings.yml +++ /dev/null @@ -1,30 +0,0 @@ -# This workflow will do a clean installation of node dependencies, cache/restore them, build the source code and run tests across different versions of node -# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions - -name: Typings CI - -on: - push: - branches: [ "main" ] - pull_request: - branches: [ "main" ] - -jobs: - build: - - strategy: - matrix: - node-version: [20.x] - os: [ubuntu-latest] - - runs-on: ${{ matrix.os }} - - steps: - - uses: actions/checkout@v3 - - name: Use Node.js ${{ matrix.node-version }} - uses: actions/setup-node@v3 - with: - node-version: ${{ matrix.node-version }} - cache: 'npm' - - run: npm ci - - run: npm run test:typings diff --git a/package-lock.json b/package-lock.json index c7a8b00..e9baa95 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,14 +13,12 @@ "resolve": "^1.22.8" }, "devDependencies": { - "@types/node": "^20.12.13", "core-assert": "^1.0.0", "is-number": "^7.0.0", "is-promise": "^4.0.0", "standard": "^17.1.0", "teenytest": "^6.0.5", - "teenytest-promise": "^1.0.0", - "typescript": "^5.4.5" + "teenytest-promise": "^1.0.0" }, "engines": { "node": ">= 0.14.0" @@ -165,16 +163,6 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, - "node_modules/@types/node": { - "version": "20.12.13", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.13.tgz", - "integrity": "sha512-gBGeanV41c1L171rR7wjbMiEpEI/l5XFQdLLfhr/REwpgDy/4U8y89+i8kRiLzDyZdOkXh+cRaTetUnCYutoXA==", - "dev": true, - "license": "MIT", - "dependencies": { - "undici-types": "~5.26.4" - } - }, "node_modules/acorn": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz", @@ -2951,20 +2939,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", - "dev": true, - "license": "Apache-2.0", - "bin": { - "tsc": "bin/tsc", - "tsserver": "bin/tsserver" - }, - "engines": { - "node": ">=14.17" - } - }, "node_modules/unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -2980,13 +2954,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", - "dev": true, - "license": "MIT" - }, "node_modules/uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", @@ -3189,15 +3156,6 @@ "integrity": "sha512-dRLjCWHYg4oaA77cxO64oO+7JwCwnIzkZPdrrC71jQmQtlhM556pwKo5bUzqvZndkVbeFLIIi+9TC40JNF5hNQ==", "dev": true }, - "@types/node": { - "version": "20.12.13", - "resolved": "https://registry.npmjs.org/@types/node/-/node-20.12.13.tgz", - "integrity": "sha512-gBGeanV41c1L171rR7wjbMiEpEI/l5XFQdLLfhr/REwpgDy/4U8y89+i8kRiLzDyZdOkXh+cRaTetUnCYutoXA==", - "dev": true, - "requires": { - "undici-types": "~5.26.4" - } - }, "acorn": { "version": "7.1.1", "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.1.1.tgz", @@ -5190,12 +5148,6 @@ "is-typed-array": "^1.1.9" } }, - "typescript": { - "version": "5.4.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.4.5.tgz", - "integrity": "sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==", - "dev": true - }, "unbox-primitive": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/unbox-primitive/-/unbox-primitive-1.0.2.tgz", @@ -5208,12 +5160,6 @@ "which-boxed-primitive": "^1.0.2" } }, - "undici-types": { - "version": "5.26.5", - "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", - "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", - "dev": true - }, "uri-js": { "version": "4.4.1", "resolved": "https://registry.npmjs.org/uri-js/-/uri-js-4.4.1.tgz", diff --git a/package.json b/package.json index 2a2ca93..75fc4c6 100644 --- a/package.json +++ b/package.json @@ -36,14 +36,12 @@ "resolve": "^1.22.8" }, "devDependencies": { - "@types/node": "^20.12.13", "core-assert": "^1.0.0", "is-number": "^7.0.0", "is-promise": "^4.0.0", "standard": "^17.1.0", "teenytest": "^6.0.5", - "teenytest-promise": "^1.0.0", - "typescript": "^5.4.5" + "teenytest-promise": "^1.0.0" }, "standard": { "globals": [ From 1fe9528ebe5bdbce79c83c978d0b4aba1ed9d540 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Fri, 31 May 2024 09:58:10 -0300 Subject: [PATCH 07/10] chore: rollback .gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index bd3452d..96978ba 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,3 @@ npm-debug.log* #ignore node_modules, as the node project is not "deployed" per se: http://www.mikealrogers.com/posts/nodemodules-in-git.html /node_modules -.DS_Store From 65e6b1b42cb37ecd60181c93ea4f0e0ca2bb8290 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Fri, 31 May 2024 09:58:53 -0300 Subject: [PATCH 08/10] refactor: use a single typings file --- index.d.ts | 23 ++++++++++- lib/canRegisterLoader.d.ts | 1 - lib/esm-import-functions.d.ts | 7 ---- lib/quibble-registered.d.mts | 5 --- lib/quibble.d.mts | 66 -------------------------------- lib/quibble.d.ts | 24 ------------ lib/thisWillRunInUserThread.d.ts | 42 -------------------- package.json | 4 +- 8 files changed, 25 insertions(+), 147 deletions(-) delete mode 100644 lib/canRegisterLoader.d.ts delete mode 100644 lib/esm-import-functions.d.ts delete mode 100644 lib/quibble-registered.d.mts delete mode 100644 lib/quibble.d.mts delete mode 100644 lib/quibble.d.ts delete mode 100644 lib/thisWillRunInUserThread.d.ts diff --git a/index.d.ts b/index.d.ts index 669ef87..f7b00d3 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,3 +1,24 @@ -import quibble from './lib/quibble.js'; +export type QuibbleConfig = { + defaultFakeCreator: (request: string) => any; +}; + +declare const quibble: ((request: string, stub?: any) => any) & { + config(userConfig: Partial): QuibbleConfig; + ignoreCallsFromThisFile(file?: string): void; + reset(hard?: boolean): void; + absolutify(relativePath: string, parentFileName?: string): string; + esm( + specifier: string, + namedExportStubs?: Record, + defaultExportStub?: any + ): Promise; + listMockedModules(): string[]; + isLoaderLoaded(): boolean; + esmImportWithPath(specifier: string): Promise<{ + modulePath: string; + moduleUrl: string; + module: any; + }>; +}; export default quibble; diff --git a/lib/canRegisterLoader.d.ts b/lib/canRegisterLoader.d.ts deleted file mode 100644 index 035dade..0000000 --- a/lib/canRegisterLoader.d.ts +++ /dev/null @@ -1 +0,0 @@ -export declare function canRegisterLoader(): boolean; diff --git a/lib/esm-import-functions.d.ts b/lib/esm-import-functions.d.ts deleted file mode 100644 index 25ff86c..0000000 --- a/lib/esm-import-functions.d.ts +++ /dev/null @@ -1,7 +0,0 @@ -export declare function dummyImportModuleToGetAtPath( - modulePath: string -): Promise; - -export declare function importOriginalModule( - fullImportPath: string -): Promise; diff --git a/lib/quibble-registered.d.mts b/lib/quibble-registered.d.mts deleted file mode 100644 index caf6e5e..0000000 --- a/lib/quibble-registered.d.mts +++ /dev/null @@ -1,5 +0,0 @@ -import { GlobalPreloadOptions } from './quibble.mjs'; - -export * from './quibble.mjs'; - -export declare function initialize({ port }: GlobalPreloadOptions): void; diff --git a/lib/quibble.d.mts b/lib/quibble.d.mts deleted file mode 100644 index b13b4ce..0000000 --- a/lib/quibble.d.mts +++ /dev/null @@ -1,66 +0,0 @@ -/// - -import { MessagePort } from 'node:worker_threads'; -import quibble from './quibble.js'; - -export default quibble; - -export declare const reset: any; - -export declare const ignoreCallsFromThisFile: any; - -export declare const config: any; - -export declare const isLoaderLoaded: any; - -export type ModuleLoaderMockInfo = { - hasDefaultExportStub: boolean; - namedExports: string[]; -}; - -export type ResolveContext = { - parentURL?: string; -}; - -export type ResolveFunction = ( - specifier: string, - context: ResolveContext, - nextResolve: ( - specifier: string, - context: ResolveContext - ) => Promise<{ - url: string; - }> -) => Promise<{ - url: string; -}>; - -export type LoadContext = { - format: string; -}; - -export type LoadFunction = ( - url: string, - context: LoadContext, - nextLoad: ( - url: string, - context: LoadContext - ) => Promise<{ - source: string | SharedArrayBuffer | Uint8Array; - format: string; - }> -) => Promise<{ - source: string | SharedArrayBuffer | Uint8Array; - format: string; - shortCircuit?: boolean; -}>; - -export type GlobalPreloadOptions = { - port: MessagePort; -}; - -export declare const resolve: ResolveFunction; - -export declare const load: LoadFunction; - -export declare const globalPreload: ({ port }: GlobalPreloadOptions) => string; diff --git a/lib/quibble.d.ts b/lib/quibble.d.ts deleted file mode 100644 index 84d0f6b..0000000 --- a/lib/quibble.d.ts +++ /dev/null @@ -1,24 +0,0 @@ -type QuibbleConfig = { - defaultFakeCreator: (request: string) => any; -}; - -declare const quibble: ((request: string, stub?: any) => any) & { - config(userConfig: Partial): QuibbleConfig; - ignoreCallsFromThisFile(file?: string): void; - reset(hard?: boolean): void; - absolutify(relativePath: string, parentFileName?: string): string; - esm( - specifier: string, - namedExportStubs?: Record, - defaultExportStub?: any - ): Promise; - listMockedModules(): string[]; - isLoaderLoaded(): boolean; - esmImportWithPath(specifier: string): Promise<{ - modulePath: string; - moduleUrl: string; - module: any; - }>; -}; - -export default quibble; diff --git a/lib/thisWillRunInUserThread.d.ts b/lib/thisWillRunInUserThread.d.ts deleted file mode 100644 index 357882e..0000000 --- a/lib/thisWillRunInUserThread.d.ts +++ /dev/null @@ -1,42 +0,0 @@ -/// - -import { MessagePort } from 'node:worker_threads'; - -export type ResetFunction = () => void; - -export type AddMockedModuleFunction = ( - moduleUrl: string, - options: { - namedExportStubs: Record; - defaultExportStub: any; - } -) => void; - -export type ListMockedModulesFunction = () => string[]; - -export type UserToLoaderCommunication = { - reset: ResetFunction; - addMockedModule: AddMockedModuleFunction; - listMockedModules: ListMockedModulesFunction; -}; - -export type QuibbleUserState = { - quibbledModules: Map; -}; - -export type QuibbleLoaderState = { - quibbledModules: Map; - stubModuleGeneration: number; -}; - -export type GlobalThis = typeof globalThis & { - [key: symbol]: - | QuibbleUserState - | UserToLoaderCommunication - | QuibbleLoaderState; -}; - -export declare const thisWillRunInUserThread: ( - globalThis: GlobalThis, - port: MessagePort -) => void; diff --git a/package.json b/package.json index 75fc4c6..0fb9eea 100644 --- a/package.json +++ b/package.json @@ -4,10 +4,12 @@ "description": "Makes it easy to replace require'd dependencies.", "homepage": "https://github.com/testdouble/quibble", "main": "./index.js", + "types": "./index.d.ts", "exports": { ".": { "require": "./lib/quibble.js", - "import": "./lib/quibble.mjs" + "import": "./lib/quibble.mjs", + "types": "./index.d.ts" }, "./package.json": "./package.json" }, From 1fb9b7c1930309196e798999ca4d8f3be81fe968 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Fri, 31 May 2024 10:00:07 -0300 Subject: [PATCH 09/10] chore: remove tsconfig.json --- tsconfig.json | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 tsconfig.json diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index e930e76..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "include": ["index.d.ts", "lib/**/*.d.ts"], - "compilerOptions": { - "forceConsistentCasingInFileNames": true, - "isolatedModules": true, - "strict": true, - "alwaysStrict": true, - "strictFunctionTypes": true, - "noUnusedLocals": true, - "noImplicitAny": true, - "esModuleInterop": true, - "skipLibCheck": false, - "noEmit": true, - } -} From 740168adde695409ea0701acd44edb2694c466f0 Mon Sep 17 00:00:00 2001 From: wellwelwel <46850407+wellwelwel@users.noreply.github.com> Date: Fri, 31 May 2024 10:00:49 -0300 Subject: [PATCH 10/10] chore: remove typings build script --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 0fb9eea..6daafc4 100644 --- a/package.json +++ b/package.json @@ -24,7 +24,6 @@ "test:example-esm-auto-loader": "node test/esm-lib/supports-auto-load.js not || (cd example-esm && npm i && npm run test-auto-loader)", "test:smells": "bash ./test/require-smell-test.sh", "test:ci": "npm test && npm run test:esm && npm run test:no-loader-esm && npm run test:esm-auto-loader && npm run style && npm run test:example && npm run test:example-esm && npm run test:example-esm-auto-loader && npm run test:smells", - "test:typings": "tsc", "preversion": "git pull --rebase && npm run test:ci", "postversion": "git push && git push --tags && npm publish" },