Skip to content

Commit 39bfbb4

Browse files
chore(data-prefetch): use rollup to bundle data-prefetch (#2983)
Co-authored-by: Zack Jackson <[email protected]> Co-authored-by: ScriptedAlchemy <[email protected]>
1 parent 44ac346 commit 39bfbb4

File tree

9 files changed

+134
-39
lines changed

9 files changed

+134
-39
lines changed

apps/manifest-demo/webpack-host/project.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,5 @@
124124
}
125125
}
126126
},
127-
"tags": [],
128-
"implicitDependencies": ["typescript"]
127+
"tags": []
129128
}

packages/data-prefetch/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024-present nieyan(nyqykk)
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

packages/data-prefetch/package.json

Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,57 +15,60 @@
1515
},
1616
"exports": {
1717
".": {
18-
"import": "./dist/esm/index.js",
19-
"require": "./dist/index.js",
20-
"types": "./dist/index.d.ts"
18+
"import": "./dist/index.esm.js",
19+
"require": "./dist/index.cjs",
20+
"types": "./dist/index.cjs.d.ts"
2121
},
2222
"./react": {
23-
"import": "./dist/esm/react/index.js",
24-
"require": "./dist/react/index.js",
25-
"types": "./dist/react/index.d.ts"
23+
"import": "./dist/react.esm.js",
24+
"require": "./dist/react.cjs.js",
25+
"types": "./dist/react.cjs.d.ts"
2626
},
2727
"./cli": {
28-
"import": "./dist/esm/cli/index.js",
29-
"require": "./dist/cli/index.js",
30-
"types": "./dist/cli/index.d.ts"
28+
"import": "./dist/cli.esm.js",
29+
"require": "./dist/cli.cjs.js",
30+
"types": "./dist/cli.cjs.d.ts"
3131
},
3232
"./babel-plugin": {
33-
"import": "./dist/esm/cli/babel.js",
34-
"require": "./dist/cli/babel.js",
35-
"types": "./dist/cli/babel.d.ts"
33+
"import": "./dist/babel.esm.js",
34+
"require": "./dist/babel.cjs.js",
35+
"types": "./dist/babel.cjs.d.ts"
3636
},
3737
"./universal": {
38-
"import": "./dist/esm/universal/index.js",
39-
"require": "./dist/universal/index.js",
40-
"types": "./dist/universal/index.d.ts"
38+
"import": "./dist/universal.esm.js",
39+
"require": "./dist/universal.cjs.js",
40+
"types": "./dist/universal.cjs.d.ts"
4141
},
4242
"./shared": {
43-
"import": "./dist/esm/shared/index.js",
44-
"require": "./dist/shared/index.js",
45-
"types": "./dist/shared/index.d.ts"
43+
"import": "./dist/shared.esm.js",
44+
"require": "./dist/shared.cjs.js",
45+
"types": "./dist/shared/.cjs.d.ts"
4646
}
4747
},
4848
"typesVersions": {
4949
"*": {
5050
".": [
51-
"./dist/index.d.ts"
51+
"./dist/index.cjs.d.ts"
5252
],
5353
"react": [
54-
"./dist/react/index.d.ts"
54+
"./dist/react.cjs.d.ts"
5555
],
5656
"cli": [
57-
"./dist/cli/index.d.ts"
57+
"./dist/cli.cjs.d.ts"
5858
],
5959
"universal": [
60-
"./dist/universal/index.d.ts"
60+
"./dist/universal.cjs.d.ts"
6161
],
6262
"shared": [
63-
"./dist/shared/index.d.ts"
63+
"./dist/shared.cjs.d.ts"
64+
],
65+
"babel-plugin": [
66+
"./dist/babel.cjs.d.ts"
6467
]
6568
}
6669
},
67-
"main": "dist/index.js",
68-
"module": "dist/esm/index.js",
70+
"main": "dist/index.cjs",
71+
"module": "dist/index.esm.js",
6972
"peerDependencies": {
7073
"react": ">=16.9.0",
7174
"react-dom": ">=16.9.0"

packages/data-prefetch/project.json

Lines changed: 46 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,61 @@
11
{
2-
"name": "module-federation/data-prefetch",
2+
"name": "data-prefetch",
33
"$schema": "../../node_modules/nx/schemas/project-schema.json",
44
"sourceRoot": "packages/data-prefetch/src",
55
"projectType": "library",
66
"targets": {
77
"build": {
8-
"executor": "nx:run-commands",
8+
"executor": "@nx/rollup:rollup",
9+
"outputs": ["{options.outputPath}"],
910
"options": {
10-
"commands": ["npm run build --prefix packages/data-prefetch"]
11+
"outputPath": "packages/data-prefetch/dist",
12+
"main": "packages/data-prefetch/src/index.ts",
13+
"tsConfig": "packages/data-prefetch/tsconfig.lib.json",
14+
"assets": [],
15+
"project": "packages/data-prefetch/package.json",
16+
"rollupConfig": "packages/data-prefetch/rollup.config.js",
17+
"compiler": "swc",
18+
"format": ["cjs", "esm"]
1119
}
1220
},
1321
"test": {
22+
"executor": "@nx/jest:jest",
23+
"outputs": ["{workspaceRoot}/coverage/{projectRoot}"],
24+
"options": {
25+
"jestConfig": "packages/data-prefetch/jest.config.js",
26+
"passWithNoTests": true
27+
},
28+
"configurations": {
29+
"ci": {
30+
"ci": true,
31+
"codeCoverage": true
32+
}
33+
}
34+
},
35+
"lint": {
36+
"executor": "@nx/linter:eslint",
37+
"outputs": ["{options.outputFile}"],
38+
"options": {
39+
"lintFilePatterns": [
40+
"packages/data-prefetch/**/*.ts",
41+
"packages/data-prefetch/package.json"
42+
]
43+
}
44+
},
45+
"pre-release": {
1446
"executor": "nx:run-commands",
1547
"options": {
16-
"commands": ["npm run test --prefix packages/data-prefetch"]
48+
"parallel": false,
49+
"commands": [
50+
{
51+
"command": "nx run data-prefetch:test",
52+
"forwardAllArgs": false
53+
},
54+
{
55+
"command": "nx run data-prefetch:build",
56+
"forwardAllArgs": false
57+
}
58+
]
1759
}
1860
}
1961
},
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const copy = require('rollup-plugin-copy');
2+
3+
module.exports = (rollupConfig, _projectOptions) => {
4+
rollupConfig.plugins.push(
5+
copy({
6+
targets: [
7+
{
8+
src: 'packages/data-prefetch/LICENSE',
9+
dest: 'packages/data-prefetch/dist',
10+
},
11+
],
12+
}),
13+
);
14+
rollupConfig.input = {
15+
index: 'packages/data-prefetch/src/index.ts',
16+
react: 'packages/data-prefetch/src/react/index.ts',
17+
cli: 'packages/data-prefetch/src/cli/index.ts',
18+
babel: 'packages/data-prefetch/src/cli/babel.ts',
19+
universal: 'packages/data-prefetch/src/universal/index.ts',
20+
plugin: 'packages/data-prefetch/src/plugin.ts',
21+
shared: 'packages/data-prefetch/src/shared/index.ts',
22+
};
23+
rollupConfig.external = [/@module-federation/];
24+
return rollupConfig;
25+
};

packages/data-prefetch/src/cli/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ export class PrefetchPlugin implements WebpackPluginInstance {
4747
this.options.runtimePlugins = [];
4848
}
4949

50-
const runtimePath = path.resolve(__dirname, '../esm/plugin.js');
51-
const sharedPath = path.resolve(__dirname, '../esm/shared/index.js');
50+
const runtimePath = path.resolve(__dirname, './plugin.esm.js');
51+
const sharedPath = path.resolve(__dirname, './shared.esm.js');
5252
if (!this.options.runtimePlugins?.includes(runtimePath)) {
5353
this.options.runtimePlugins!.push(runtimePath);
5454
}

packages/data-prefetch/tsconfig.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,6 @@
2222
"@src/*": ["./src/*"]
2323
}
2424
},
25-
"include": ["src", "../../global.d.ts", "__tests__/**/*", "tsup.config.ts"],
25+
"include": ["src", "../../global.d.ts", "__tests__/**/*"],
2626
"exclude": ["node_modules/**/*", "../node_modules"]
2727
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "../../dist/out-tsc",
5+
"declaration": true,
6+
"types": ["node"]
7+
},
8+
"include": ["src/**/*.ts"],
9+
"exclude": ["jest.config.ts", "src/**/*.spec.ts", "src/**/*.test.ts"]
10+
}

packages/enhanced/test/ConfigTestCases.template.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,8 @@ const describeCases = (config) => {
352352
) {
353353
return;
354354
}
355-
const startDate = new Date('2024-09-20'); // Set the start date to today (or another specific date)
356-
const currentDate = new Date();
357-
358-
const oneMonthInMs = 30 * 24 * 60 * 60 * 1000;
359355

360356
if (
361-
currentDate.getTime() - startDate.getTime() >= oneMonthInMs &&
362357
checkArrayExpectation(
363358
testDirectory,
364359
jsonStats,

0 commit comments

Comments
 (0)