@shijiu/jsview 2.1.364-test.0 → 2.1.366-test.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shijiu/jsview",
3
- "version": "2.1.364-test.0",
3
+ "version": "2.1.366-test.0",
4
4
  "bin": {
5
5
  "jsview-post-build": "./tools/jsview-post-build.js",
6
6
  "jsview-post-install": "./tools/jsview-post-install.js"
@@ -0,0 +1,70 @@
1
+ diff --git a/node_modules/@originjs/vite-plugin-federation/dist/index.js b/node_modules/@originjs/vite-plugin-federation/dist/index.js
2
+ index 980b8e3..48baae5 100644
3
+ --- a/node_modules/@originjs/vite-plugin-federation/dist/index.js
4
+ +++ b/node_modules/@originjs/vite-plugin-federation/dist/index.js
5
+ @@ -970,8 +970,11 @@ function prodExposePlugin(options) {
6
+ const filepathMap = /* @__PURE__ */ new Map();
7
+ const getFilename = (name) => path.parse(path.parse(name).name).name;
8
+ const cssBundlesMap = Object.keys(bundle).filter((name) => path.extname(name) === ".css").reduce((res, name) => {
9
+ - const filename = getFilename(name);
10
+ - res.set(filename, bundle[name]);
11
+ +// JsView Removed >>>
12
+ +// JsView js代码中已内嵌css
13
+ + //const filename = getFilename(name);
14
+ + //res.set(filename, bundle[name]);
15
+ +// JsView Removed <<<
16
+ return res;
17
+ }, /* @__PURE__ */ new Map());
18
+ remoteEntryChunk.code = remoteEntryChunk.code.replace(
19
+ @@ -1481,6 +1484,16 @@ function federation(options) {
20
+ }
21
+ builderInfo.builder = "vite";
22
+ builderInfo.assetsDir = ((_b = config == null ? void 0 : config.build) == null ? void 0 : _b.assetsDir) ?? "assets";
23
+ +// JsView Added >>>
24
+ +// 根据chunkFile路径设置assetsDir
25
+ + let chunkFileNames = config.build.rollupOptions.output.chunkFileNames;
26
+ + if (typeof (chunkFileNames) === 'function') {
27
+ + chunkFileNames = chunkFileNames({name: 'test.js'})
28
+ + }
29
+ + const jsDir = path.dirname(chunkFileNames);
30
+ + builderInfo.assetsDir = jsDir;
31
+ + console.log("builderInfo",builderInfo);
32
+ +// JsView Added <<<
33
+ },
34
+ configureServer(server) {
35
+ var _a;
36
+ diff --git a/node_modules/@originjs/vite-plugin-federation/dist/index.mjs b/node_modules/@originjs/vite-plugin-federation/dist/index.mjs
37
+ index 57bae8f..9320e8d 100644
38
+ --- a/node_modules/@originjs/vite-plugin-federation/dist/index.mjs
39
+ +++ b/node_modules/@originjs/vite-plugin-federation/dist/index.mjs
40
+ @@ -953,8 +953,11 @@ function prodExposePlugin(options) {
41
+ const filepathMap = /* @__PURE__ */ new Map();
42
+ const getFilename = (name) => parse(parse(name).name).name;
43
+ const cssBundlesMap = Object.keys(bundle).filter((name) => extname(name) === ".css").reduce((res, name) => {
44
+ - const filename = getFilename(name);
45
+ - res.set(filename, bundle[name]);
46
+ +// JsView Removed >>>
47
+ +// JsView js代码中已内嵌css
48
+ + //const filename = getFilename(name);
49
+ + //res.set(filename, bundle[name]);
50
+ +// JsView Removed <<<
51
+ return res;
52
+ }, /* @__PURE__ */ new Map());
53
+ remoteEntryChunk.code = remoteEntryChunk.code.replace(
54
+ @@ -1464,6 +1467,16 @@ function federation(options) {
55
+ }
56
+ builderInfo.builder = "vite";
57
+ builderInfo.assetsDir = ((_b = config == null ? void 0 : config.build) == null ? void 0 : _b.assetsDir) ?? "assets";
58
+ +// JsView Added >>>
59
+ +// 根据chunkFile路径设置assetsDir
60
+ + let chunkFileNames = config.build.rollupOptions.output.chunkFileNames;
61
+ + if (typeof (chunkFileNames) === 'function') {
62
+ + chunkFileNames = chunkFileNames({name: 'test.js'})
63
+ + }
64
+ + const jsDir = path.dirname(chunkFileNames);
65
+ + builderInfo.assetsDir = jsDir;
66
+ + console.log("builderInfo",builderInfo);
67
+ +// JsView Added <<<
68
+ },
69
+ configureServer(server) {
70
+ var _a;
@@ -244,7 +244,8 @@ function getOptions(framework)
244
244
 
245
245
  const cacheName = (framework == 'vue' ? '.vite' : '.cache');
246
246
  options.cacheDir = path.resolve(options.modulesDir, cacheName);
247
- options.baseUrlFile = path.resolve(options.cacheDir, 'jsview', 'network.mjs');
247
+ options.cacheJsViewDir = path.resolve(options.cacheDir, 'jsview');
248
+ options.baseUrlFile = path.resolve(options.cacheJsViewDir, 'network.mjs');
248
249
 
249
250
  return options;
250
251
  }
@@ -5,44 +5,16 @@ import fs from 'node:fs';
5
5
  import path from 'node:path';
6
6
  import {
7
7
  checkNodeVersion,
8
- downloadFileAsync,
9
8
  execCommand,
10
9
  getOptions,
11
- loadPackageObject,
12
10
  parseArguments,
13
- savePackageObject,
14
11
  Logger,
15
- unzipFile,
16
12
  } from './jsview-common.mjs';
17
13
  import { assert } from 'node:console';
18
14
 
19
15
  async function updateToFederationBase(options)
20
16
  {
21
17
  Logger.Info('Updating package.json...');
22
- const pkgObj = loadPackageObject(options.projectDir);
23
- if(!pkgObj.scripts) {
24
- pkgObj.scripts = {};
25
- }
26
-
27
- var postInstall = pkgObj.scripts.postinstall ?? '';
28
- if(postInstall.includes('npx patch-package') == false) {
29
- if(postInstall) {
30
- postInstall += ' && '
31
- }
32
-
33
- postInstall += 'npx patch-package'
34
- }
35
-
36
- pkgObj.scripts.postinstall = postInstall;
37
-
38
- savePackageObject(options.projectDir, pkgObj);
39
-
40
- Logger.Info('Downloading patches ...');
41
- const url = 'https://gitlab.cluster.qcast.cn/mirror/jsview-module-federation-demo/-/raw/main/patches.zip';
42
- const filePath = path.resolve(options.projectDir, 'patches.zip');
43
- await downloadFileAsync(url, filePath, options.projectDir)
44
-
45
- unzipFile(filePath, options.projectDir, options.projectDir);
46
18
 
47
19
  const devDeps = '@originjs/vite-plugin-federation@1.3.4'
48
20
  Logger.Info('Installing ' + devDeps + ' ...');
@@ -50,10 +22,6 @@ async function updateToFederationBase(options)
50
22
  execCommand('npm ci');
51
23
  }
52
24
 
53
- function getRemoteEntryUrl(options)
54
- {
55
- }
56
-
57
25
  function genFederationUrl(options)
58
26
  {
59
27
  var content = '';
@@ -69,7 +37,7 @@ const jsviewLoaderUrl = remoteDomain + '/js/JsViewLoader.js'`
69
37
  }
70
38
  }
71
39
 
72
- return content
40
+ return content;
73
41
  }
74
42
 
75
43
  function genConfigFunction(options)
@@ -110,14 +78,16 @@ function getHostConfig()
110
78
  }
111
79
 
112
80
  content += `
113
- shared: [`;
114
- if(options.jsviewMode == 'share') {
81
+ shared: {`;
82
+ if(options.jsviewMode == 'shared') {
115
83
  content += `
116
- 'jsview',`;
84
+ '@shijiu/jsview-vue': {},
85
+ jsview: { packagePath: '@shijiu/jsview-vue' },`;
117
86
  }
118
87
  content += `
119
- 'vue',
120
- ]
88
+ vue: {},
89
+ 'vue-router': {},
90
+ },
121
91
  }
122
92
 
123
93
  return config
@@ -345,8 +315,8 @@ async function main(argv)
345
315
  }
346
316
  options.mode = argv.mode;
347
317
 
348
- if(argv.jsview != 'share' && argv.jsview != 'expose') {
349
- Logger.ErrorAndExit('Invalid --jsview, its value can only be "share" or "expose".');
318
+ if(argv.jsview != 'shared' && argv.jsview != 'expose') {
319
+ Logger.ErrorAndExit('Invalid --jsview, its value can only be "shared" or "expose".');
350
320
  }
351
321
  options.jsviewMode = argv.jsview;
352
322
 
@@ -377,7 +347,7 @@ async function main(argv)
377
347
 
378
348
  const requiredUsages = {
379
349
  '--mode': 'Project mode. the value is "remote" or "host"',
380
- '--jsview': 'jsview mode. the value is "share" or "expose"',
350
+ '--jsview': 'jsview mode. the value is "shared" or "expose"',
381
351
  };
382
352
  const optionalUsages = {
383
353
  '--remote-domain': 'remote domain. Host use this domain to access remote module.',
@@ -114,7 +114,7 @@ function checkPatches(options, pkgNeedPatch, skipCheckVersion)
114
114
 
115
115
  function installPatches(options, pkgNeedPatch)
116
116
  {
117
- Logger.Info('Patching JsView:');
117
+ Logger.Info('Stage 1: Installing patches for JsView:');
118
118
  for (const pkgName of pkgNeedPatch) {
119
119
  const patchSrc = path.resolve(options.jsviewPatchModulesDir, pkgName);
120
120
  const patchDest = path.resolve(options.modulesDir, pkgName);
@@ -126,6 +126,86 @@ function installPatches(options, pkgNeedPatch)
126
126
  rmSync(options.projectDir, options.cacheDir);
127
127
  }
128
128
 
129
+ function getPatchListRecursive(patchDir)
130
+ {
131
+ var patchList = [];
132
+
133
+ const pkgNameArray = fs.readdirSync(patchDir);
134
+ for (const pkgName of pkgNameArray) {
135
+ const pkgFullPath = path.resolve(patchDir, pkgName);
136
+
137
+ const isDirectory = fs.statSync(pkgFullPath).isDirectory();
138
+ if(isDirectory) {
139
+ const subPatchList = getPatchListRecursive(pkgFullPath);
140
+ patchList = [...patchList, ...subPatchList];
141
+ } else {
142
+ if(pkgFullPath.endsWith('.patch') == false) {
143
+ continue;
144
+ }
145
+
146
+ patchList.push(pkgFullPath);
147
+ }
148
+ }
149
+
150
+ return patchList;
151
+ }
152
+
153
+ function autoPatchPackages(options)
154
+ {
155
+ Logger.Info('Stage 2: Auto patching packages:');
156
+
157
+ const patchCacheDir = path.resolve(options.cacheJsViewDir, 'patches');
158
+ fs.mkdirSync(patchCacheDir, { recursive: true, force: true });
159
+
160
+ const patchInfo = {};
161
+ const patchList = getPatchListRecursive(options.jsviewPatchModulesDir);
162
+ for (const patchFullPath of patchList) {
163
+ const patchRelativePath = path.relative(options.jsviewPatchModulesDir, patchFullPath);
164
+ const patchNameAndVersion = path.dirname(patchRelativePath);
165
+ const patchVersion = path.basename(patchNameAndVersion);
166
+ const patchName = path.dirname(patchNameAndVersion);
167
+
168
+ if(!patchInfo[patchName]) {
169
+ patchInfo[patchName] = [];
170
+ }
171
+ patchInfo[patchName].push(patchVersion);
172
+ }
173
+
174
+ for(const [patchName, patchVersions] of Object.entries(patchInfo)) {
175
+ const pkgFullDir = path.resolve(options.modulesDir, patchName);
176
+ const pkgJsonFullPath = path.resolve(pkgFullDir, 'package.json');
177
+ if(fs.existsSync(pkgJsonFullPath) == false) {
178
+ continue;
179
+ }
180
+
181
+ const pkgObj = loadPackageObject(pkgFullDir);
182
+ const pkgVersion = pkgObj.version;
183
+ if(patchVersions.includes(pkgVersion) == false) {
184
+ Logger.Warn(' Patch file for ' + patchName + '@' + pkgVersion + ' is not found.');
185
+ continue;
186
+ }
187
+
188
+ const patchFullDir = path.resolve(options.jsviewPatchModulesDir, patchName, pkgVersion);
189
+ const patchFiles = fs.readdirSync(patchFullDir);
190
+ for (const file of patchFiles) {
191
+ if(file.endsWith('.patch') == false) {
192
+ continue;
193
+ }
194
+
195
+ const copyFromPath = path.resolve(patchFullDir, file);
196
+ const copyToPath = path.resolve(patchCacheDir, file);
197
+ cpSync(options.projectDir, copyFromPath, copyToPath);
198
+ }
199
+ }
200
+
201
+ const hasPatches = fs.readdirSync(patchCacheDir);
202
+ if(hasPatches && hasPatches.length > 0) {
203
+ execCommand('npx patch-package --patch-dir ' + path.relative(options.projectDir, patchCacheDir));
204
+ } else {
205
+ Logger.Info(' No patch files found.');
206
+ }
207
+ }
208
+
129
209
  async function printRevision(options)
130
210
  {
131
211
  const jsviewVersionURL = url.pathToFileURL(options.jsviewDomRevisionFile);
@@ -188,6 +268,8 @@ function doPostInstall(framework, pkgNeedPatch, skipCheckVersion)
188
268
 
189
269
  installPatches(options, pkgNeedPatch);
190
270
 
271
+ autoPatchPackages(options);
272
+
191
273
  printRevision(options);
192
274
  }
193
275