-
-
Notifications
You must be signed in to change notification settings - Fork 582
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(type):
rspack
function type in CJS require (#8169)
* fix: the cjs require type and default type * chore: update * chore: update the test case * chore: update * chore: update * chore: update * chore: update * chore: update * chore: update the index * fix: fix the api-extractor:ci command * chore: update the type
- Loading branch information
Showing
7 changed files
with
76 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
/** @type {import('ts-jest/dist/types').JestConfigWithTsJest} */ | ||
const config = { | ||
preset: 'ts-jest', | ||
testEnvironment: '../../scripts/test/patch-node-env.cjs', | ||
testTimeout: process.env.CI ? 200000 : 30000, | ||
testMatch: ['<rootDir>/tests/**/*.test.ts', '<rootDir>/tests/**/*.test.js'], | ||
watchPathIgnorePatterns: ['<rootDir>/tests/.*/dist'], | ||
extensionsToTreatAsEsm: ['.mts'], | ||
globals: {'ts-jest': {tsconfig: '<rootDir>/tests/tsconfig.json'}}, | ||
cache: false, | ||
prettierPath: require.resolve('prettier-2') | ||
preset: "ts-jest", | ||
testEnvironment: "../../scripts/test/patch-node-env.cjs", | ||
testTimeout: process.env.CI ? 200000 : 30000, | ||
testMatch: ["<rootDir>/tests/**/*.test.ts", "<rootDir>/tests/**/*.test.js"], | ||
watchPathIgnorePatterns: ["<rootDir>/tests/.*/dist"], | ||
extensionsToTreatAsEsm: [".mts"], | ||
transform: { | ||
"^.+\\.(ts)?$": ["ts-jest", { tsconfig: "<rootDir>/tests/tsconfig.json" }] | ||
}, | ||
cache: false, | ||
prettierPath: require.resolve("prettier-2") | ||
}; | ||
|
||
module.exports = config; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import rspackCjsRequire, { | ||
rspack as rspackCjsNamedRequire | ||
} from "@rspack/core"; | ||
import assert from "node:assert"; | ||
|
||
type IsFunction<T> = T extends (...args: any[]) => any ? true : false; | ||
|
||
// https://github.com/web-infra-dev/rspack/issues/8095 | ||
describe("js-api-type should be correct when requiring from @rspack/core", () => { | ||
it("cjs default require", async () => { | ||
// const rspack = require('@rspack/core') | ||
type Truthy = IsFunction<typeof rspackCjsRequire>; | ||
const truthy: Truthy = true; | ||
truthy; | ||
assert(rspackCjsNamedRequire.BannerPlugin); | ||
assert(typeof rspackCjsNamedRequire === "function"); | ||
const compiler = rspackCjsNamedRequire({}); | ||
assert(compiler); | ||
}); | ||
|
||
it("cjs named require", async () => { | ||
// const { rspack } = require('@rspack/core') | ||
type Truthy = IsFunction<typeof rspackCjsNamedRequire>; | ||
const truthy: Truthy = true; | ||
truthy; | ||
assert(rspackCjsNamedRequire.BannerPlugin); | ||
assert(typeof rspackCjsNamedRequire === "function"); | ||
const compiler = rspackCjsNamedRequire({}); | ||
assert(compiler); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import rspackEsmDefaultImport, { | ||
rspack as rspackEsmNamedImport | ||
} from "@rspack/core"; | ||
import assert from "node:assert"; | ||
|
||
type IsFunction<T> = T extends (...args: any[]) => any ? true : false; | ||
|
||
// https://github.com/web-infra-dev/rspack/issues/8095 | ||
describe("js-api-type should be correct when importing from @rspack/core", () => { | ||
it("esm default import", async () => { | ||
// rspack has no default export now | ||
type Falsy = IsFunction<typeof rspackEsmDefaultImport>; | ||
const falsy: Falsy = false; | ||
falsy; | ||
assert(rspackEsmDefaultImport.BannerPlugin); | ||
}); | ||
|
||
it("esm named import", async () => { | ||
type Truthy = IsFunction<typeof rspackEsmNamedImport>; | ||
const truthy: Truthy = true; | ||
truthy; | ||
assert(rspackEsmNamedImport.BannerPlugin); | ||
assert(typeof rspackEsmNamedImport === "function"); | ||
const compiler = rspackEsmNamedImport({}); | ||
assert(compiler); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11f20e1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Benchmark detail: Open
11f20e1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Ran ecosystem CI: Open