@nizza/devkit 0.1.0-alpha.11 → 0.1.0-alpha.13

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.
Files changed (38) hide show
  1. package/dist/cjs/executors/update-executors-file/index.cjs +2 -2
  2. package/dist/cjs/index.cjs +7 -7
  3. package/dist/cjs/node_modules/.pnpm/@vitejs_plugin-basic-ssl@1.0.2_vite@5.0.4/node_modules/@vitejs/plugin-basic-ssl/dist/chunks/certificate.cjs +19578 -0
  4. package/dist/cjs/node_modules/.pnpm/@vitejs_plugin-basic-ssl@1.0.2_vite@5.0.4/node_modules/@vitejs/plugin-basic-ssl/dist/index.cjs +40 -0
  5. package/dist/cjs/shared/utils.cjs +2 -2
  6. package/dist/cjs/{vite-utils → vitejs}/config-builder/configs/base.cjs +3 -3
  7. package/dist/cjs/{vite-utils → vitejs}/config-builder/configs/lib.cjs +2 -1
  8. package/dist/cjs/{vite-utils → vitejs}/config-builder/plugins.cjs +17 -3
  9. package/dist/cjs/{vite-utils → vitejs}/config-builder/shared/types.cjs +1 -0
  10. package/dist/cjs/{vite-utils → vitejs}/plugins/third-party-css-inject/utils.cjs +1 -3
  11. package/dist/esm/executors/update-executors-file/index.mjs +2 -2
  12. package/dist/esm/index.mjs +7 -7
  13. package/dist/esm/node_modules/.pnpm/@vitejs_plugin-basic-ssl@1.0.2_vite@5.0.4/node_modules/@vitejs/plugin-basic-ssl/dist/chunks/certificate.mjs +19576 -0
  14. package/dist/esm/node_modules/.pnpm/@vitejs_plugin-basic-ssl@1.0.2_vite@5.0.4/node_modules/@vitejs/plugin-basic-ssl/dist/index.mjs +35 -0
  15. package/dist/esm/{vite-utils → vitejs}/config-builder/configs/base.mjs +4 -4
  16. package/dist/esm/{vite-utils → vitejs}/config-builder/configs/lib.mjs +2 -1
  17. package/dist/esm/{vite-utils → vitejs}/config-builder/plugins.mjs +17 -4
  18. package/dist/esm/{vite-utils → vitejs}/config-builder/shared/types.mjs +1 -0
  19. package/dist/esm/{vite-utils → vitejs}/plugins/third-party-css-inject/utils.mjs +1 -3
  20. package/package.json +2 -4
  21. /package/dist/cjs/{vite-utils → vitejs}/config-builder/configs/app.cjs +0 -0
  22. /package/dist/cjs/{vite-utils → vitejs}/config-builder/configs/index.cjs +0 -0
  23. /package/dist/cjs/{vite-utils → vitejs}/config-builder/configs/script.cjs +0 -0
  24. /package/dist/cjs/{vite-utils → vitejs}/config-builder/main.cjs +0 -0
  25. /package/dist/cjs/{vite-utils → vitejs}/config-builder/shared/utils/helpers.cjs +0 -0
  26. /package/dist/cjs/{vite-utils → vitejs}/config-builder/shared/utils/projectConfig.cjs +0 -0
  27. /package/dist/cjs/{vite-utils → vitejs}/config-builder/shared/utils/viteCommand.cjs +0 -0
  28. /package/dist/cjs/{vite-utils → vitejs}/plugins/shadow-dom-inject-css/index.cjs +0 -0
  29. /package/dist/cjs/{vite-utils → vitejs}/plugins/third-party-css-inject/main.cjs +0 -0
  30. /package/dist/esm/{vite-utils → vitejs}/config-builder/configs/app.mjs +0 -0
  31. /package/dist/esm/{vite-utils → vitejs}/config-builder/configs/index.mjs +0 -0
  32. /package/dist/esm/{vite-utils → vitejs}/config-builder/configs/script.mjs +0 -0
  33. /package/dist/esm/{vite-utils → vitejs}/config-builder/main.mjs +0 -0
  34. /package/dist/esm/{vite-utils → vitejs}/config-builder/shared/utils/helpers.mjs +0 -0
  35. /package/dist/esm/{vite-utils → vitejs}/config-builder/shared/utils/projectConfig.mjs +0 -0
  36. /package/dist/esm/{vite-utils → vitejs}/config-builder/shared/utils/viteCommand.mjs +0 -0
  37. /package/dist/esm/{vite-utils → vitejs}/plugins/shadow-dom-inject-css/index.mjs +0 -0
  38. /package/dist/esm/{vite-utils → vitejs}/plugins/third-party-css-inject/main.mjs +0 -0
@@ -0,0 +1,35 @@
1
+ import path from 'node:path';
2
+ import { promises } from 'node:fs';
3
+
4
+ const defaultCacheDir = "node_modules/.vite";
5
+ function viteBasicSslPlugin() {
6
+ return {
7
+ name: "vite:basic-ssl",
8
+ async configResolved(config) {
9
+ const certificate = await getCertificate((config.cacheDir ?? defaultCacheDir) + "/basic-ssl");
10
+ const https = () => ({ cert: certificate, key: certificate });
11
+ config.server.https = Object.assign({}, config.server.https, https());
12
+ config.preview.https = Object.assign({}, config.preview.https, https());
13
+ }
14
+ };
15
+ }
16
+ async function getCertificate(cacheDir) {
17
+ const cachePath = path.join(cacheDir, "_cert.pem");
18
+ try {
19
+ const [stat, content] = await Promise.all([
20
+ promises.stat(cachePath),
21
+ promises.readFile(cachePath, "utf8")
22
+ ]);
23
+ if (Date.now() - stat.ctime.valueOf() > 30 * 24 * 60 * 60 * 1e3) {
24
+ throw new Error("cache is outdated.");
25
+ }
26
+ return content;
27
+ } catch {
28
+ const content = (await import('./chunks/certificate.mjs')).createCertificate();
29
+ promises.mkdir(cacheDir, { recursive: true }).then(() => promises.writeFile(cachePath, content)).catch(() => {
30
+ });
31
+ return content;
32
+ }
33
+ }
34
+
35
+ export { viteBasicSslPlugin as default, getCertificate };
@@ -1,12 +1,12 @@
1
- import { bundleAnalysisPlugin, basePlugins } from '../plugins.mjs';
1
+ import { existsSync } from 'fs';
2
+ import { resolve } from 'path';
3
+ import { bundleAnalysisPlugin, httpsServerPlugin, basePlugins } from '../plugins.mjs';
2
4
  import { Target, ViteMode, Flag, Stage } from '../shared/types.mjs';
3
5
  import { getPlugins, when } from '../shared/utils/helpers.mjs';
4
6
  import 'minimatch';
5
7
  import '../../../shared/logger.mjs';
6
8
  import '@nx/devkit';
7
9
  import 'crypto';
8
- import { existsSync } from 'fs';
9
- import { resolve } from 'path';
10
10
  import 'chalk';
11
11
  import 'mri';
12
12
  import 'vite';
@@ -30,7 +30,7 @@ const getBaseConfig = (ctx)=>{
30
30
  const envFilePath = existsSync(resolve(path, 'src', envPath)) ? envPath : fallbackEnvPath;
31
31
  return {
32
32
  envPrefix,
33
- plugins: getPlugins(ctx, basePlugins, bundleAnalysisPlugin),
33
+ plugins: getPlugins(ctx, basePlugins, httpsServerPlugin, bundleAnalysisPlugin),
34
34
  resolve: {
35
35
  alias: {
36
36
  ...when(resolveEnvs.default && !omittedStages.includes(stage), {
@@ -38,7 +38,8 @@ const getLibConfig = (ctx)=>{
38
38
  name,
39
39
  entry,
40
40
  formats: [
41
- 'es'
41
+ 'es',
42
+ 'cjs'
42
43
  ],
43
44
  fileName: (format)=>`index.${format === 'es' ? 'mjs' : 'cjs'}`
44
45
  },
@@ -17,6 +17,7 @@ import 'crypto';
17
17
  import 'fs';
18
18
  import 'chalk';
19
19
  import 'mri';
20
+ import viteBasicSslPlugin from '../../node_modules/.pnpm/@vitejs_plugin-basic-ssl@1.0.2_vite@5.0.4/node_modules/@vitejs/plugin-basic-ssl/dist/index.mjs';
20
21
 
21
22
  /**
22
23
  * Base plugins configuration for apps and libs.
@@ -63,13 +64,13 @@ import 'mri';
63
64
  filename: 'bundle-analysis.html'
64
65
  })
65
66
  ],
66
- condition: ({ viteCmd })=>viteCmd.flags?.[Flag.ANALYZE] === 'true'
67
+ condition: ({ viteCmd })=>viteCmd.flags?.[Flag.ANALYZE]
67
68
  };
68
69
  /**
69
70
  * Plugin configuration for injecting CSS into JS files
70
71
  * using vite-plugin-css-injected-by-js.
71
72
  */ const injectCssByJsPlugin = {
72
- generate: (_)=>[
73
+ generate: ()=>[
73
74
  cssInjectedByJsPlugin()
74
75
  ],
75
76
  condition: ({ projectConfig })=>!projectConfig.shadowDom
@@ -78,10 +79,22 @@ import 'mri';
78
79
  * Plugin configuration for injecting CSS into Shadow Dom.
79
80
  * using local plugin.
80
81
  */ const injectCssIntoShadowDomPlugin = {
81
- generate: (_)=>[
82
+ generate: ()=>[
82
83
  injectCssIntoShadowDom()
83
84
  ],
84
85
  condition: ({ projectConfig })=>projectConfig.shadowDom
85
86
  };
87
+ /**
88
+ * Use the plugin @vitejs/plugin-basic-ssl to create a SSL
89
+ * certificate and create https server.
90
+ */ const httpsServerPlugin = {
91
+ generate: ()=>[
92
+ viteBasicSslPlugin()
93
+ ],
94
+ condition: ({ viteCmd })=>{
95
+ console.log('🚀 ~ file: plugins.ts:92 ~ viteCmd.flags:', viteCmd.flags);
96
+ return viteCmd.flags?.[Flag.HTTPS];
97
+ }
98
+ };
86
99
 
87
- export { basePlugins, bundleAnalysisPlugin, dtsPlugin, injectCssByJsPlugin, injectCssIntoShadowDomPlugin };
100
+ export { basePlugins, bundleAnalysisPlugin, dtsPlugin, httpsServerPlugin, injectCssByJsPlugin, injectCssIntoShadowDomPlugin };
@@ -22,6 +22,7 @@ var Flag;
22
22
  Flag["ANALYZE"] = "analyze";
23
23
  Flag["VERBOSE"] = "verbose";
24
24
  Flag["VERBOSE_ALIAS"] = "v";
25
+ Flag["HTTPS"] = "https";
25
26
  })(Flag || (Flag = {}));
26
27
  var Target;
27
28
  (function(Target) {
@@ -64,13 +64,11 @@ async function buildCSSInjectionCode(execute) {
64
64
  */ function injectionCSSCodePlugin(execute) {
65
65
  return {
66
66
  name: 'vite:third-party-css-inject',
67
- // @ts-ignore
68
67
  resolveId (id) {
69
68
  if (id == cssInjectedByJsId) {
70
69
  return id;
71
70
  }
72
71
  },
73
- // @ts-ignore
74
72
  load (id) {
75
73
  if (id == cssInjectedByJsId) {
76
74
  let executeJs = [];
@@ -84,7 +82,7 @@ async function buildCSSInjectionCode(execute) {
84
82
  return `try{if(typeof document != 'undefined'){
85
83
  const waitForElement=${waitForElement.toString()};
86
84
  ${executeJs.join(' ')}
87
- }}catch(e){console.error('vite'-third-party-css-inject-plugin', e);}`;
85
+ }}catch(e){console.error('vite:third-party-css-inject', e);}`;
88
86
  }
89
87
  }
90
88
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nizza/devkit",
3
- "version": "0.1.0-alpha.11",
3
+ "version": "0.1.0-alpha.13",
4
4
  "type": "module",
5
5
  "main": "dist/cjs/index.cjs",
6
6
  "module": "dist/esm/index.mjs",
@@ -39,10 +39,8 @@
39
39
  "rollup": "^4.2.0",
40
40
  "rollup-plugin-copy": "^3.5.0",
41
41
  "rollup-plugin-delete": "^2.0.0",
42
- "rollup-plugin-dts": "^6.1.0",
43
42
  "rollup-plugin-dts-bundle-generator": "^1.4.0",
44
- "rollup-plugin-swc3": "^0.10.3",
45
- "rollup-plugin-ts": "^3.4.5"
43
+ "rollup-plugin-swc3": "^0.10.3"
46
44
  },
47
45
  "peerDependencies": {
48
46
  "@nx/devkit": "17.0.2",