@deot/dev-dever 2.5.0 → 2.5.2

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/dist/index.cjs CHANGED
@@ -80,7 +80,7 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
80
80
  }
81
81
  if (options.dryRun)
82
82
  return devShared.Shell.spawn(`echo development`);
83
- const { cwd, workspace, packageOptionsMap, packageDirsMap } = locals;
83
+ const { cwd, workspace, packageOptionsMap, packageDirsMap, subpackagesMap } = locals;
84
84
  const packageFolderName = devShared.Locals.getPackageFolderName(options.packageName);
85
85
  const packageOptions = packageOptionsMap[packageFolderName];
86
86
  const packageDir = packageDirsMap[packageFolderName];
@@ -102,26 +102,35 @@ const run = (options) => devShared.Utils.autoCatch(async () => {
102
102
  host: true
103
103
  }
104
104
  };
105
+ const devOptions = {
106
+ ...options,
107
+ workspace,
108
+ entries,
109
+ html,
110
+ subpackagesMap,
111
+ // 这个是给外部调用(z.)?dev.config.ts用的
112
+ useVue: false,
113
+ useReact: false
114
+ };
115
+ const { vuePackage: isVuePackage, reactPackage: isReactPackage } = options;
116
+ devOptions.useVue = !!isVuePackage;
117
+ devOptions.useReact = !!isReactPackage;
105
118
  if (fs$1.existsSync(`${cwd}/z.dev.config.ts`)) {
106
119
  options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(cwd, "./z.dev.config.ts"));
107
120
  } else if (fs$1.existsSync(`${cwd}/dev.config.ts`)) {
108
121
  options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(cwd, "./dev.config.ts"));
109
122
  } else {
123
+ process.env.USE_VUE = isVuePackage ? "1" : "";
124
+ process.env.USE_REACT = isReactPackage ? "1" : "";
110
125
  options$.configFile = path__namespace.relative(cwd, path__namespace.resolve(dirname, "../shared.config.ts"));
111
- const { vuePackage, reactPackage } = options;
112
- if (vuePackage) {
126
+ if (isVuePackage) {
113
127
  options$ = vite.mergeConfig(sharedVueConfig, options$);
114
128
  }
115
- if (reactPackage) {
129
+ if (isReactPackage) {
116
130
  options$ = vite.mergeConfig(sharedReactConfig, options$);
117
131
  }
118
132
  }
119
- process.env.DEV_OPTIONS = encodeURIComponent(JSON.stringify({
120
- ...options,
121
- workspace,
122
- entries,
123
- html
124
- }));
133
+ process.env.DEV_OPTIONS = encodeURIComponent(JSON.stringify(devOptions));
125
134
  const server = await vite.createServer(options$);
126
135
  const $server = await server.listen();
127
136
  const { local = [], network = [] } = $server.resolvedUrls || {};
package/dist/index.es.js CHANGED
@@ -56,7 +56,7 @@ const run = (options) => Utils.autoCatch(async () => {
56
56
  }
57
57
  if (options.dryRun)
58
58
  return Shell.spawn(`echo development`);
59
- const { cwd, workspace, packageOptionsMap, packageDirsMap } = locals;
59
+ const { cwd, workspace, packageOptionsMap, packageDirsMap, subpackagesMap } = locals;
60
60
  const packageFolderName = Locals.getPackageFolderName(options.packageName);
61
61
  const packageOptions = packageOptionsMap[packageFolderName];
62
62
  const packageDir = packageDirsMap[packageFolderName];
@@ -78,26 +78,35 @@ const run = (options) => Utils.autoCatch(async () => {
78
78
  host: true
79
79
  }
80
80
  };
81
+ const devOptions = {
82
+ ...options,
83
+ workspace,
84
+ entries,
85
+ html,
86
+ subpackagesMap,
87
+ // 这个是给外部调用(z.)?dev.config.ts用的
88
+ useVue: false,
89
+ useReact: false
90
+ };
91
+ const { vuePackage: isVuePackage, reactPackage: isReactPackage } = options;
92
+ devOptions.useVue = !!isVuePackage;
93
+ devOptions.useReact = !!isReactPackage;
81
94
  if (fs$1.existsSync(`${cwd}/z.dev.config.ts`)) {
82
95
  options$.configFile = path.relative(cwd, path.resolve(cwd, "./z.dev.config.ts"));
83
96
  } else if (fs$1.existsSync(`${cwd}/dev.config.ts`)) {
84
97
  options$.configFile = path.relative(cwd, path.resolve(cwd, "./dev.config.ts"));
85
98
  } else {
99
+ process.env.USE_VUE = isVuePackage ? "1" : "";
100
+ process.env.USE_REACT = isReactPackage ? "1" : "";
86
101
  options$.configFile = path.relative(cwd, path.resolve(dirname, "../shared.config.ts"));
87
- const { vuePackage, reactPackage } = options;
88
- if (vuePackage) {
102
+ if (isVuePackage) {
89
103
  options$ = mergeConfig(sharedVueConfig, options$);
90
104
  }
91
- if (reactPackage) {
105
+ if (isReactPackage) {
92
106
  options$ = mergeConfig(sharedReactConfig, options$);
93
107
  }
94
108
  }
95
- process.env.DEV_OPTIONS = encodeURIComponent(JSON.stringify({
96
- ...options,
97
- workspace,
98
- entries,
99
- html
100
- }));
109
+ process.env.DEV_OPTIONS = encodeURIComponent(JSON.stringify(devOptions));
101
110
  const server = await createServer(options$);
102
111
  const $server = await server.listen();
103
112
  const { local = [], network = [] } = $server.resolvedUrls || {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deot/dev-dever",
3
- "version": "2.5.0",
3
+ "version": "2.5.2",
4
4
  "type": "module",
5
5
  "main": "dist/index.es.js",
6
6
  "types": "dist/index.d.ts",
@@ -23,7 +23,7 @@
23
23
  "dependencies": {
24
24
  "@deot/dev-react": "^2.5.0",
25
25
  "@deot/dev-shared": "^2.5.0",
26
- "@deot/dev-vue": "^2.5.0",
26
+ "@deot/dev-vue": "^2.5.1",
27
27
  "ejs": "^3.1.9",
28
28
  "vite": "^4.4.9"
29
29
  },
package/shared.config.ts CHANGED
@@ -16,11 +16,7 @@ const cwd = process.cwd();
16
16
 
17
17
  // devOptions
18
18
  const devOptions = JSON.parse(decodeURIComponent(process.env.DEV_OPTIONS || '{}'));
19
- const { workspace, html } = devOptions;
20
-
21
- // alias
22
- const replacement = (name: string) => path.resolve(cwd, `./packages/${name}/src`);
23
- const { name } = createRequire(cwd)(path.resolve(cwd, workspace ? `${workspace}/index` : '', 'package.json'));
19
+ const { workspace, html, subpackagesMap } = devOptions;
24
20
 
25
21
  const generateIndexHtml = (url: string, inject: string) => {
26
22
  let contents = '';
@@ -100,6 +96,13 @@ const getVirtualHtml = async (url: string) => {
100
96
  }
101
97
  };
102
98
 
99
+
100
+ // alias
101
+ const require$ = createRequire(cwd);
102
+ const getPackageName = (name: string) => (require$(path.resolve(cwd, workspace ? `${workspace}/${name}` : '', 'package.json'))).name;
103
+ const replacement = (name: string, isSubpackage?: boolean) => path.resolve(cwd, `./packages/${name}`, isSubpackage ? 'index.ts' : './src');
104
+ const name = getPackageName('index');
105
+
103
106
  export default defineConfig({
104
107
  resolve: workspace
105
108
  ? {
@@ -108,6 +111,15 @@ export default defineConfig({
108
111
  find: new RegExp(`^${name}$`),
109
112
  replacement: replacement('index')
110
113
  },
114
+ ...Object.keys(subpackagesMap).reduce((pre, cur: string) => {
115
+ if (subpackagesMap[cur].length) {
116
+ pre.push({
117
+ find: new RegExp(`^${getPackageName(cur)}$`),
118
+ replacement: replacement(cur, true)
119
+ });
120
+ }
121
+ return pre;
122
+ }, [] as any),
111
123
  {
112
124
 
113
125
  find: new RegExp(`^${name}-(.*?)$`),