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

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 (191) hide show
  1. package/dist/cjs/executors/deploy/helpers.cjs +26 -0
  2. package/dist/cjs/executors/deploy/index.cjs +22 -0
  3. package/dist/cjs/executors/environments/helpers.cjs +62 -0
  4. package/dist/cjs/executors/environments/index.cjs +60 -0
  5. package/dist/cjs/executors/publish/helpers.cjs +51 -0
  6. package/dist/cjs/executors/publish/index.cjs +53 -0
  7. package/dist/cjs/executors/shared/utils.cjs +67 -0
  8. package/dist/cjs/executors/update-executors-file/helpers.cjs +64 -0
  9. package/dist/cjs/executors/update-executors-file/index.cjs +38 -0
  10. package/dist/cjs/executors/vtex-link/constants.cjs +9 -0
  11. package/dist/cjs/executors/vtex-link/helpers.cjs +206 -0
  12. package/dist/cjs/executors/vtex-link/index.cjs +30 -0
  13. package/dist/cjs/index.cjs +56 -0
  14. package/dist/cjs/scripts/changeset-pre-mode.cjs +41 -0
  15. package/dist/cjs/scripts/index.cjs +7 -0
  16. package/dist/cjs/shared/logger.cjs +98 -0
  17. package/dist/cjs/shared/utils.cjs +36 -0
  18. package/dist/cjs/vite-utils/config-builder/configs/app.cjs +13 -0
  19. package/dist/cjs/vite-utils/config-builder/configs/base.cjs +58 -0
  20. package/dist/cjs/vite-utils/config-builder/configs/index.cjs +36 -0
  21. package/dist/cjs/vite-utils/config-builder/configs/lib.cjs +57 -0
  22. package/dist/cjs/vite-utils/config-builder/configs/script.cjs +46 -0
  23. package/dist/cjs/vite-utils/config-builder/main.cjs +42 -0
  24. package/dist/cjs/vite-utils/config-builder/plugins.cjs +93 -0
  25. package/dist/cjs/vite-utils/config-builder/shared/types.cjs +33 -0
  26. package/dist/cjs/vite-utils/config-builder/shared/utils/helpers.cjs +115 -0
  27. package/dist/cjs/vite-utils/config-builder/shared/utils/projectConfig.cjs +114 -0
  28. package/dist/cjs/vite-utils/config-builder/shared/utils/viteCommand.cjs +59 -0
  29. package/dist/{src/vite/plugins/shadow-dom-inject-css/index.js → cjs/vite-utils/plugins/shadow-dom-inject-css/index.cjs} +4 -19
  30. package/dist/{src/vite/plugins/third-party-css-inject/main.js → cjs/vite-utils/plugins/third-party-css-inject/main.cjs} +13 -14
  31. package/dist/{src/vite/plugins/third-party-css-inject/utils.js → cjs/vite-utils/plugins/third-party-css-inject/utils.cjs} +9 -21
  32. package/dist/esm/executors/deploy/helpers.mjs +22 -0
  33. package/dist/esm/executors/deploy/index.mjs +20 -0
  34. package/dist/esm/executors/deploy/schema.json +41 -0
  35. package/dist/esm/executors/environments/helpers.mjs +58 -0
  36. package/dist/esm/executors/environments/index.mjs +58 -0
  37. package/dist/esm/executors/environments/schema.json +9 -0
  38. package/dist/esm/executors/publish/helpers.mjs +48 -0
  39. package/dist/esm/executors/publish/index.mjs +51 -0
  40. package/dist/esm/executors/publish/schema.json +19 -0
  41. package/dist/esm/executors/shared/utils.mjs +62 -0
  42. package/dist/esm/executors/update-executors-file/helpers.mjs +59 -0
  43. package/dist/esm/executors/update-executors-file/index.mjs +36 -0
  44. package/dist/esm/executors/update-executors-file/schema.json +9 -0
  45. package/dist/esm/executors/vtex-link/constants.mjs +5 -0
  46. package/dist/esm/executors/vtex-link/helpers.mjs +192 -0
  47. package/dist/esm/executors/vtex-link/index.mjs +28 -0
  48. package/dist/esm/executors/vtex-link/schema.json +25 -0
  49. package/dist/esm/index.mjs +12 -0
  50. package/dist/esm/scripts/changeset-pre-mode.mjs +39 -0
  51. package/dist/esm/scripts/index.mjs +1 -0
  52. package/dist/{src/logger.js → esm/shared/logger.mjs} +28 -39
  53. package/dist/esm/shared/utils.mjs +33 -0
  54. package/dist/esm/vite-utils/config-builder/configs/app.mjs +11 -0
  55. package/dist/{src/vite/config-builder/configs/base.js → esm/vite-utils/config-builder/configs/base.mjs} +23 -22
  56. package/dist/esm/vite-utils/config-builder/configs/index.mjs +30 -0
  57. package/dist/{src/vite/config-builder/configs/lib.js → esm/vite-utils/config-builder/configs/lib.mjs} +16 -18
  58. package/dist/esm/vite-utils/config-builder/configs/script.mjs +44 -0
  59. package/dist/esm/vite-utils/config-builder/main.mjs +40 -0
  60. package/dist/esm/vite-utils/config-builder/plugins.mjs +87 -0
  61. package/dist/{src/vite/config-builder/shared/types.js → esm/vite-utils/config-builder/shared/types.mjs} +2 -27
  62. package/dist/{src/vite/config-builder/shared/utils/helpers.d.ts → esm/vite-utils/config-builder/shared/utils/helpers.mjs} +33 -24
  63. package/dist/esm/vite-utils/config-builder/shared/utils/projectConfig.mjs +109 -0
  64. package/dist/esm/vite-utils/config-builder/shared/utils/viteCommand.mjs +56 -0
  65. package/dist/esm/vite-utils/plugins/shadow-dom-inject-css/index.mjs +27 -0
  66. package/dist/esm/vite-utils/plugins/third-party-css-inject/main.mjs +45 -0
  67. package/dist/esm/vite-utils/plugins/third-party-css-inject/utils.mjs +97 -0
  68. package/dist/index.d.ts +367 -0
  69. package/executors.json +29 -0
  70. package/package.json +52 -6
  71. package/dist/package.json +0 -13
  72. package/dist/src/executors/deploy/executor.d.ts +0 -11
  73. package/dist/src/executors/deploy/executor.d.ts.map +0 -1
  74. package/dist/src/executors/deploy/executor.js +0 -27
  75. package/dist/src/executors/deploy/helpers.d.ts +0 -4
  76. package/dist/src/executors/deploy/helpers.d.ts.map +0 -1
  77. package/dist/src/executors/deploy/helpers.js +0 -40
  78. package/dist/src/executors/environments/executor.d.ts +0 -16
  79. package/dist/src/executors/environments/executor.d.ts.map +0 -1
  80. package/dist/src/executors/environments/executor.js +0 -59
  81. package/dist/src/executors/environments/helpers.d.ts +0 -21
  82. package/dist/src/executors/environments/helpers.d.ts.map +0 -1
  83. package/dist/src/executors/environments/helpers.js +0 -63
  84. package/dist/src/executors/publish/executor.d.ts +0 -12
  85. package/dist/src/executors/publish/executor.d.ts.map +0 -1
  86. package/dist/src/executors/publish/executor.js +0 -58
  87. package/dist/src/executors/publish/helpers.d.ts +0 -19
  88. package/dist/src/executors/publish/helpers.d.ts.map +0 -1
  89. package/dist/src/executors/publish/helpers.js +0 -52
  90. package/dist/src/executors/shared/index.d.ts +0 -3
  91. package/dist/src/executors/shared/index.d.ts.map +0 -1
  92. package/dist/src/executors/shared/index.js +0 -7
  93. package/dist/src/executors/shared/types.d.ts +0 -4
  94. package/dist/src/executors/shared/types.d.ts.map +0 -1
  95. package/dist/src/executors/shared/types.js +0 -4
  96. package/dist/src/executors/shared/utils.d.ts +0 -34
  97. package/dist/src/executors/shared/utils.d.ts.map +0 -1
  98. package/dist/src/executors/shared/utils.js +0 -74
  99. package/dist/src/executors/update-executors-file/executor.d.ts +0 -12
  100. package/dist/src/executors/update-executors-file/executor.d.ts.map +0 -1
  101. package/dist/src/executors/update-executors-file/executor.js +0 -46
  102. package/dist/src/executors/update-executors-file/helpers.d.ts +0 -24
  103. package/dist/src/executors/update-executors-file/helpers.d.ts.map +0 -1
  104. package/dist/src/executors/update-executors-file/helpers.js +0 -70
  105. package/dist/src/executors/update-executors-file/types.d.ts +0 -14
  106. package/dist/src/executors/update-executors-file/types.d.ts.map +0 -1
  107. package/dist/src/executors/update-executors-file/types.js +0 -4
  108. package/dist/src/executors/vtex-link/constants.d.ts +0 -4
  109. package/dist/src/executors/vtex-link/constants.d.ts.map +0 -1
  110. package/dist/src/executors/vtex-link/constants.js +0 -24
  111. package/dist/src/executors/vtex-link/executor.d.ts +0 -5
  112. package/dist/src/executors/vtex-link/executor.d.ts.map +0 -1
  113. package/dist/src/executors/vtex-link/executor.js +0 -35
  114. package/dist/src/executors/vtex-link/helpers.d.ts +0 -77
  115. package/dist/src/executors/vtex-link/helpers.d.ts.map +0 -1
  116. package/dist/src/executors/vtex-link/helpers.js +0 -187
  117. package/dist/src/executors/vtex-link/types.d.ts +0 -12
  118. package/dist/src/executors/vtex-link/types.d.ts.map +0 -1
  119. package/dist/src/executors/vtex-link/types.js +0 -4
  120. package/dist/src/index.d.ts +0 -2
  121. package/dist/src/index.d.ts.map +0 -1
  122. package/dist/src/index.js +0 -6
  123. package/dist/src/logger.d.ts +0 -34
  124. package/dist/src/logger.d.ts.map +0 -1
  125. package/dist/src/scripts/changeset-pre-mode.d.ts +0 -2
  126. package/dist/src/scripts/changeset-pre-mode.d.ts.map +0 -1
  127. package/dist/src/scripts/changeset-pre-mode.js +0 -41
  128. package/dist/src/shared/index.d.ts +0 -2
  129. package/dist/src/shared/index.d.ts.map +0 -1
  130. package/dist/src/shared/index.js +0 -6
  131. package/dist/src/shared/utils.d.ts +0 -11
  132. package/dist/src/shared/utils.d.ts.map +0 -1
  133. package/dist/src/shared/utils.js +0 -22
  134. package/dist/src/vite/config-builder/configs/app.d.ts +0 -4
  135. package/dist/src/vite/config-builder/configs/app.d.ts.map +0 -1
  136. package/dist/src/vite/config-builder/configs/app.js +0 -19
  137. package/dist/src/vite/config-builder/configs/base.d.ts +0 -4
  138. package/dist/src/vite/config-builder/configs/base.d.ts.map +0 -1
  139. package/dist/src/vite/config-builder/configs/index.d.ts +0 -7
  140. package/dist/src/vite/config-builder/configs/index.d.ts.map +0 -1
  141. package/dist/src/vite/config-builder/configs/index.js +0 -28
  142. package/dist/src/vite/config-builder/configs/lib.d.ts +0 -4
  143. package/dist/src/vite/config-builder/configs/lib.d.ts.map +0 -1
  144. package/dist/src/vite/config-builder/configs/script.d.ts +0 -4
  145. package/dist/src/vite/config-builder/configs/script.d.ts.map +0 -1
  146. package/dist/src/vite/config-builder/configs/script.js +0 -42
  147. package/dist/src/vite/config-builder/index.d.ts +0 -3
  148. package/dist/src/vite/config-builder/index.d.ts.map +0 -1
  149. package/dist/src/vite/config-builder/index.js +0 -7
  150. package/dist/src/vite/config-builder/main.d.ts +0 -10
  151. package/dist/src/vite/config-builder/main.d.ts.map +0 -1
  152. package/dist/src/vite/config-builder/main.js +0 -37
  153. package/dist/src/vite/config-builder/plugins.d.ts +0 -30
  154. package/dist/src/vite/config-builder/plugins.d.ts.map +0 -1
  155. package/dist/src/vite/config-builder/plugins.js +0 -88
  156. package/dist/src/vite/config-builder/shared/index.d.ts +0 -3
  157. package/dist/src/vite/config-builder/shared/index.d.ts.map +0 -1
  158. package/dist/src/vite/config-builder/shared/index.js +0 -7
  159. package/dist/src/vite/config-builder/shared/types.d.ts +0 -155
  160. package/dist/src/vite/config-builder/shared/types.d.ts.map +0 -1
  161. package/dist/src/vite/config-builder/shared/utils/helpers.d.ts.map +0 -1
  162. package/dist/src/vite/config-builder/shared/utils/helpers.js +0 -61
  163. package/dist/src/vite/config-builder/shared/utils/index.d.ts +0 -4
  164. package/dist/src/vite/config-builder/shared/utils/index.d.ts.map +0 -1
  165. package/dist/src/vite/config-builder/shared/utils/index.js +0 -8
  166. package/dist/src/vite/config-builder/shared/utils/projectConfig.d.ts +0 -60
  167. package/dist/src/vite/config-builder/shared/utils/projectConfig.d.ts.map +0 -1
  168. package/dist/src/vite/config-builder/shared/utils/projectConfig.js +0 -85
  169. package/dist/src/vite/config-builder/shared/utils/viteCommand.d.ts +0 -24
  170. package/dist/src/vite/config-builder/shared/utils/viteCommand.d.ts.map +0 -1
  171. package/dist/src/vite/config-builder/shared/utils/viteCommand.js +0 -54
  172. package/dist/src/vite/index.d.ts +0 -3
  173. package/dist/src/vite/index.d.ts.map +0 -1
  174. package/dist/src/vite/index.js +0 -7
  175. package/dist/src/vite/plugins/index.d.ts +0 -3
  176. package/dist/src/vite/plugins/index.d.ts.map +0 -1
  177. package/dist/src/vite/plugins/index.js +0 -7
  178. package/dist/src/vite/plugins/shadow-dom-inject-css/index.d.ts +0 -8
  179. package/dist/src/vite/plugins/shadow-dom-inject-css/index.d.ts.map +0 -1
  180. package/dist/src/vite/plugins/third-party-css-inject/index.d.ts +0 -4
  181. package/dist/src/vite/plugins/third-party-css-inject/index.d.ts.map +0 -1
  182. package/dist/src/vite/plugins/third-party-css-inject/index.js +0 -13
  183. package/dist/src/vite/plugins/third-party-css-inject/main.d.ts +0 -17
  184. package/dist/src/vite/plugins/third-party-css-inject/main.d.ts.map +0 -1
  185. package/dist/src/vite/plugins/third-party-css-inject/utils.d.ts +0 -5
  186. package/dist/src/vite/plugins/third-party-css-inject/utils.d.ts.map +0 -1
  187. /package/dist/{src → cjs}/executors/deploy/schema.json +0 -0
  188. /package/dist/{src → cjs}/executors/environments/schema.json +0 -0
  189. /package/dist/{src → cjs}/executors/publish/schema.json +0 -0
  190. /package/dist/{src → cjs}/executors/update-executors-file/schema.json +0 -0
  191. /package/dist/{src → cjs}/executors/vtex-link/schema.json +0 -0
@@ -0,0 +1,56 @@
1
+ import chalk from 'chalk';
2
+ import argv from 'mri';
3
+ import { loadEnv } from 'vite';
4
+ import { ViteMode, Stage, Target } from '../types.mjs';
5
+
6
+ /**
7
+ * Retrieves the Vite command details.
8
+ *
9
+ * @param {ViteMode} mode - The Vite mode.
10
+ * @returns {ViteCommand} - The command details.
11
+ *
12
+ * @example
13
+ * const command = getViteCommand(ViteMode.PROD);
14
+ * // Outputs: { stage: Stage.PROD, target: 'build', flags: {} }
15
+ */ function getViteCommand(mode) {
16
+ const nxEnv = loadEnv(mode, process.cwd(), 'NX');
17
+ const nxCommandString = process?.env?.['npm_package_scripts_nx'];
18
+ const modeIsProd = mode === ViteMode.PROD;
19
+ const stage = (nxEnv?.['NX_TASK_TARGET_CONFIGURATION']) ?? (modeIsProd ? Stage.PROD : Stage.DEV);
20
+ const target = nxEnv?.['NX_TASK_TARGET_TARGET'] ?? Target.BUILD;
21
+ const flags = getViteCmdFlags(nxCommandString);
22
+ const showIn = {
23
+ prod: (...args)=>modeIsProd && console.log(...args),
24
+ dev: (...args)=>!modeIsProd && console.log(...args)
25
+ };
26
+ try {
27
+ showIn.prod(chalk.cyan('Build Stage:'), chalk.green(stage));
28
+ showIn.dev(chalk.green(' ➜ '), chalk.bold.white(`Stage: `), chalk.cyan(stage));
29
+ } catch {
30
+ showIn.prod(console.log('Build Stage:', stage));
31
+ showIn.dev(console.log(` ➜ Stage: `, stage));
32
+ }
33
+ return {
34
+ stage,
35
+ target,
36
+ flags
37
+ };
38
+ }
39
+ /**
40
+ * Parses the command string to extract flags.
41
+ *
42
+ * @param {string | undefined} commandString - The command string.
43
+ * @returns {Record<string, string>} - The flags extracted from the command string.
44
+ *
45
+ * @example
46
+ * const flags = getViteCmdFlags('nx run core:build --source-maps');
47
+ * // Outputs: { 'source-maps: 'true' }
48
+ */ function getViteCmdFlags(commandString) {
49
+ if (!commandString) return {};
50
+ const cleanedCommandString = commandString.replace(/"/g, '');
51
+ const args = argv(cleanedCommandString.split(' '));
52
+ delete args['_'];
53
+ return args;
54
+ }
55
+
56
+ export { getViteCmdFlags, getViteCommand };
@@ -0,0 +1,27 @@
1
+ function injectCssIntoShadowDom() {
2
+ const fileRegex = /\.(css)$/;
3
+ let server;
4
+ return {
5
+ name: 'nizza:inject-css-into-shadow-dom',
6
+ configureServer (_server) {
7
+ server = _server;
8
+ },
9
+ transform (src, id) {
10
+ if (server) {
11
+ const relativeId = /\/lib\/.*/.exec(id)?.[0].replace('/lib/', '');
12
+ if (fileRegex.test(id)) {
13
+ server.ws.send({
14
+ type: 'custom',
15
+ event: 'inject-css-into-shadow-dom:hot-updated',
16
+ data: {
17
+ id: relativeId,
18
+ content: src
19
+ }
20
+ });
21
+ }
22
+ }
23
+ }
24
+ };
25
+ }
26
+
27
+ export { injectCssIntoShadowDom };
@@ -0,0 +1,45 @@
1
+ import { removeLinkStyleSheets, buildCSSInjectionCode } from './utils.mjs';
2
+
3
+ /**
4
+ * Inject the CSS compiled with JS.
5
+ *
6
+ * @return {Plugin}
7
+ */ function thirdPartyCssInjectPlugin({ topExecutionPriority, execute } = {
8
+ topExecutionPriority: true,
9
+ execute: []
10
+ }) {
11
+ //Globally so we can add it to legacy and non-legacy bundle.
12
+ let config;
13
+ return {
14
+ apply: 'build',
15
+ enforce: 'post',
16
+ name: 'nizza:third-party-css-inject',
17
+ configResolved (_config) {
18
+ config = _config;
19
+ },
20
+ async generateBundle (opts, bundle) {
21
+ if (config.build.ssr) {
22
+ return;
23
+ }
24
+ const htmlFiles = Object.keys(bundle).filter((i)=>i.endsWith('.html'));
25
+ const cssAssets = Object.keys(bundle).filter((i)=>bundle[i]?.type == 'asset' && bundle[i]?.fileName.endsWith('.css'));
26
+ const jsAssets = Object.keys(bundle).filter((i)=>bundle[i]?.type == 'chunk' && bundle[i]?.fileName.match(/.[cm]?js$/) != null && !bundle[i]?.fileName.includes('polyfill'));
27
+ for (const name of htmlFiles){
28
+ const htmlChunk = bundle[name];
29
+ let replacedHtml = htmlChunk.source;
30
+ cssAssets.forEach((cssName)=>{
31
+ replacedHtml = removeLinkStyleSheets(replacedHtml, cssName);
32
+ htmlChunk.source = replacedHtml;
33
+ });
34
+ }
35
+ const jsAsset = bundle[jsAssets[0]];
36
+ const cssInjectionCode = await buildCSSInjectionCode(execute);
37
+ const appCode = jsAsset.code;
38
+ jsAsset.code = topExecutionPriority ? '' : appCode;
39
+ jsAsset.code += cssInjectionCode ? cssInjectionCode.code : '';
40
+ jsAsset.code += !topExecutionPriority ? '' : appCode;
41
+ }
42
+ };
43
+ }
44
+
45
+ export { thirdPartyCssInjectPlugin };
@@ -0,0 +1,97 @@
1
+ import { build } from 'vite';
2
+
3
+ const cssInjectedByJsId = '\0vite/all-css';
4
+ const waitForElement = (selector, observerElementName = 'body')=>{
5
+ const getElement = (selector)=>document.querySelector(selector);
6
+ return new Promise((resolve)=>{
7
+ if (getElement(selector)) return resolve(getElement(selector));
8
+ const observer = new MutationObserver(()=>{
9
+ if (getElement(selector)) {
10
+ resolve(getElement(selector));
11
+ observer.disconnect();
12
+ }
13
+ });
14
+ let observerElement = document.body;
15
+ switch(observerElementName){
16
+ case 'body':
17
+ observerElement = document.body;
18
+ break;
19
+ case 'head':
20
+ observerElement = document.head;
21
+ break;
22
+ default:
23
+ observerElement = document.body;
24
+ break;
25
+ }
26
+ observer.observe(observerElement, {
27
+ childList: true,
28
+ subtree: true
29
+ });
30
+ });
31
+ };
32
+ async function buildCSSInjectionCode(execute) {
33
+ const res = await build({
34
+ root: '',
35
+ configFile: false,
36
+ logLevel: 'error',
37
+ plugins: [
38
+ injectionCSSCodePlugin(execute)
39
+ ],
40
+ build: {
41
+ write: false,
42
+ target: 'es2015',
43
+ minify: 'esbuild',
44
+ assetsDir: '',
45
+ rollupOptions: {
46
+ input: {
47
+ 'all-css': cssInjectedByJsId
48
+ },
49
+ output: {
50
+ format: 'iife',
51
+ manualChunks: undefined
52
+ }
53
+ }
54
+ }
55
+ });
56
+ const _cssChunk = Array.isArray(res) ? res[0] : res;
57
+ if (!('output' in _cssChunk)) return null;
58
+ return _cssChunk.output[0];
59
+ }
60
+ /**
61
+ * @param {string} cssToInject
62
+ * @param {string|null} styleId
63
+ * @return {Plugin}
64
+ */ function injectionCSSCodePlugin(execute) {
65
+ return {
66
+ name: 'vite:third-party-css-inject',
67
+ // @ts-ignore
68
+ resolveId (id) {
69
+ if (id == cssInjectedByJsId) {
70
+ return id;
71
+ }
72
+ },
73
+ // @ts-ignore
74
+ load (id) {
75
+ if (id == cssInjectedByJsId) {
76
+ let executeJs = [];
77
+ if (execute?.length) {
78
+ executeJs = execute.map((executeData, index)=>{
79
+ return `waitForElement('${executeData.observer}', '${executeData.listen}').then((elm)=>{
80
+ const extra${index}=${executeData.function};extra${index}(elm)
81
+ });`;
82
+ });
83
+ }
84
+ return `try{if(typeof document != 'undefined'){
85
+ const waitForElement=${waitForElement.toString()};
86
+ ${executeJs.join(' ')}
87
+ }}catch(e){console.error('vite'-third-party-css-inject-plugin', e);}`;
88
+ }
89
+ }
90
+ };
91
+ }
92
+ function removeLinkStyleSheets(html, cssFileName) {
93
+ const removeCSS = new RegExp(`<link rel=".*"[^>]*?href=".*/?${cssFileName}"[^>]*?>`);
94
+ return html.replace(removeCSS, '');
95
+ }
96
+
97
+ export { buildCSSInjectionCode, removeLinkStyleSheets };
@@ -0,0 +1,367 @@
1
+ // Generated by dts-bundle-generator v7.2.0
2
+
3
+ import { ExecutorContext } from '@nx/devkit';
4
+ import { PreRenderedChunk } from 'rollup';
5
+ import { ConfigEnv, LibraryOptions, Plugin, PluginOption, UserConfig, ViteDevServer } from 'vite';
6
+
7
+ export type ExecutorResponse = {
8
+ success: boolean;
9
+ };
10
+ export interface ExecutorOptions {
11
+ s3BucketPath: string;
12
+ cloudFrontDistributionId: string;
13
+ cloudFrontInvalidationPaths: string[];
14
+ buildTarget: string;
15
+ skipBuild?: boolean;
16
+ }
17
+ export function deployExecutor(opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
18
+ export interface ExecutorOptions {
19
+ }
20
+ declare function runExecutor(_opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
21
+ export interface ExecutorOptions {
22
+ tag: string;
23
+ dryRun?: boolean;
24
+ }
25
+ declare function runExecutor(opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
26
+ export interface ExecutorOptions {
27
+ }
28
+ declare function runExecutor(_opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
29
+ export interface ExecutorOptions {
30
+ packageOrg: string;
31
+ rollback?: boolean;
32
+ skipLink?: boolean;
33
+ }
34
+ declare function runExecutor(opts: ExecutorOptions, ctx: ExecutorContext): Promise<ExecutorResponse>;
35
+ declare enum LogLevel {
36
+ ERROR = 0,
37
+ WARN = 1,
38
+ INFO = 2,
39
+ DEBUG = 3
40
+ }
41
+ export declare enum ViteMode {
42
+ PROD = "production",
43
+ DEV = "development"
44
+ }
45
+ /**
46
+ * Project stages, it coincides with the target configurations of the project.json of NX.
47
+ * @readonly
48
+ * @enum {string}
49
+ */
50
+ export declare enum Stage {
51
+ PROD = "prod",
52
+ DEV = "dev",
53
+ STAGING = "staging",
54
+ LOCAL = "local"
55
+ }
56
+ export declare enum ProjectType {
57
+ APP = "app",
58
+ LIB = "lib",
59
+ SCRIPT = "script"
60
+ }
61
+ export declare enum Flag {
62
+ SOURCEMAP = "source-maps",
63
+ ANALYZE = "analyze",
64
+ VERBOSE = "verbose",
65
+ VERBOSE_ALIAS = "v"
66
+ }
67
+ export declare enum Target {
68
+ BUILD = "build",
69
+ PREVIEW = "preview",
70
+ SERVE = "serve"
71
+ }
72
+ /**
73
+ * Vite Environment.
74
+ *
75
+ * @property {ViteMode} mode - Vite mode.
76
+ */
77
+ export type ViteEnv = ConfigEnv & {
78
+ mode: ViteMode;
79
+ };
80
+ /**
81
+ * Externalizing libraries.
82
+ *
83
+ * @property {boolean} default - React externalizes and other common dependencies,
84
+ * this only applies to libraries.
85
+ * @property {boolean} glob - Glob expression or list of glob expressions to exclude
86
+ * dependencies from the package.json.
87
+ */
88
+ export type ExternalizeLibs = {
89
+ default: boolean;
90
+ glob: string | string[];
91
+ };
92
+ export type ResolveEnvs = {
93
+ default: boolean;
94
+ local: boolean;
95
+ };
96
+ /**
97
+ * Project configuration.
98
+ *
99
+ * @property {ProjectType} type - Type of the project.
100
+ * @property {string} path - Path of the project.
101
+ * @property {string} entry - Path of the file entry point.
102
+ * @property {string} name - Name of the project, it is also used to define the name of the library.
103
+ * @property {string} port - Server port.
104
+ * @property {boolean} debug - Print data purification data.
105
+ * @property {boolean} dts - Control if the .d.ts files are generated, by default it is True.
106
+ * @property {Partial<ResolveEnvs>} resolveEnvs - Flag for resolving environment.
107
+ * @property {boolean} shadowDom - If component is render into shadow dom.
108
+ * @property {Partial<ExternalizeLibs>} externalizeLibs - Configuration for externalizing libraries.
109
+ * @property {LibraryOptions['fileName']} fileName - Output file name for library.
110
+ * @property {string} fileName - Prefix for chunk file name.
111
+ * @property {ViteEnv} viteEnv - Vite environment configuration.
112
+ * @property {UserConfig} overrides - Overrides for vite configuration.
113
+ */
114
+ export interface ProjectConfig {
115
+ type: ProjectType;
116
+ path: string;
117
+ entry?: string;
118
+ name?: string;
119
+ port?: number;
120
+ logLevel?: LogLevel;
121
+ dts?: boolean;
122
+ resolveEnvs?: Partial<ResolveEnvs>;
123
+ shadowDom?: boolean;
124
+ externalizeLibs?: Partial<ExternalizeLibs>;
125
+ fileName?: LibraryOptions["fileName"];
126
+ chunkPrefix?: string;
127
+ viteEnv: ViteEnv;
128
+ overrides?: UserConfig;
129
+ }
130
+ export interface ProjectConfigInitialized extends ProjectConfig {
131
+ name: string;
132
+ fileName: string;
133
+ chunkPrefix: string;
134
+ logLevel: LogLevel;
135
+ overrides: UserConfig;
136
+ shadowDom: boolean;
137
+ resolveEnvs: ResolveEnvs;
138
+ externalizeLibs: ExternalizeLibs;
139
+ }
140
+ /**
141
+ * Vite command details.
142
+ * @interface
143
+ * @property {Stage} stage - Stage of the project.
144
+ * @property {string} target - Command name.
145
+ * @property {Record<string, any>} flags - Flags for customize command.
146
+ */
147
+ export interface ViteCommand {
148
+ stage: Stage;
149
+ target: string;
150
+ flags: Record<string, any>;
151
+ }
152
+ /**
153
+ * Common project configuration.
154
+ *
155
+ * @property {string} envPrefix - Prefix in lowercase for environment variables and output files.
156
+ * @property {boolean} externalizeLibGlob - Glob expression or list of glob expressions to exclude
157
+ * dependencies from the package.json.
158
+ */
159
+ export interface CommonProjectConfig {
160
+ envPrefix: string;
161
+ externalizeLibGlob?: string | string[];
162
+ }
163
+ /**
164
+ * Config builder context.
165
+ *
166
+ * @property {CommonProjectConfig} commonConfig - Common configuration for the project.
167
+ * @property {ProjectConfigInitialized} projectConfig - Initialized project configuration.
168
+ * @property {ViteCommandDetail} viteCmd - Vite command details.
169
+ */
170
+ export interface Context {
171
+ commonConfig: CommonProjectConfig;
172
+ projectConfig: ProjectConfigInitialized;
173
+ viteCmd: ViteCommand;
174
+ localPkgJson: Record<string, any>;
175
+ }
176
+ /**
177
+ * Interface for plugin configuration.
178
+ */
179
+ export interface PluginConfig {
180
+ /**
181
+ * Generates plugin(s) based on the provided configuration.
182
+ * @param {Context} ctx - The main configuration object.
183
+ * @returns {any[]} An array of plugins.
184
+ */
185
+ generate: (ctx: Context) => any[];
186
+ /**
187
+ * Condition to determine if the plugin(s) should be included.
188
+ * @param {Context} ctx - The main configuration object.
189
+ * @returns {boolean} True if the plugin(s) should be included; false otherwise.
190
+ */
191
+ condition?: (ctx: Context) => boolean;
192
+ }
193
+ /**
194
+ * Deeply merges two objects, combining their properties.
195
+ *
196
+ * @param {Record<string, any>} v1 - The first object.
197
+ * @param {Record<string, any>} v2 - The second object.
198
+ * @returns {Record<string, any>} - The merged object.
199
+ *
200
+ * @example
201
+ * const obj1 = { a: 1, b: { c: 2 } };
202
+ * const obj2 = { b: { d: 3 } };
203
+ * const merged = deepMerge(obj1, obj2); // Outputs: { a: 1, b: { c: 2, d: 3 } }
204
+ */
205
+ export declare function deepMerge(v1: Record<string, any>, v2: Record<string, any>): Record<string, any>;
206
+ /**
207
+ * Generates a name for js files.
208
+ *
209
+ * @param {string} [prefix] - An optional prefix for the chunk name.
210
+ * @returns - A function that takes an item and generates a chunk name.
211
+ *
212
+ * @example
213
+ * const generateChunkName = chunkName('prefix');
214
+ * const name = generateChunkName({ name: 'example' }); // Outputs: "prefix-example-Aj3_Dk7_2j.js"
215
+ */
216
+ export declare const chunkName: (prefix?: string) => (x: PreRenderedChunk) => string;
217
+ /**
218
+ * Returns the given object if the condition is true, otherwise returns null.
219
+ *
220
+ * @param {any} condition - The condition to evaluate.
221
+ * @param {Record<string, any>} obj - The object to return if the condition is true.
222
+ * @returns {Record<string, any> | null} - The object or null based on the condition.
223
+ *
224
+ * @example
225
+ * const obj = { a: 1 };
226
+ * const result = when(true, obj); // Outputs: { a: 1 }
227
+ * const result2 = when(false, obj); // Outputs: {}
228
+ */
229
+ export declare const when: (condition: any, obj: Record<string, any>) => Record<string, any>;
230
+ /**
231
+ * Filters and generates plugin configurations based on conditions and the provided context.
232
+ *
233
+ * @param {Context} ctx - The main configuration object.
234
+ * @returns {any[]} - An array of generated plugin configurations.
235
+ */
236
+ export declare const getPlugins: (ctx: Context, ...pluginConfigs: PluginConfig[]) => PluginOption[];
237
+ /**
238
+ * Gets the paths to the tsconfig files for all relevant projects.
239
+ *
240
+ * @returns {string[]} - An array containing paths to tsconfig files for both app and lib projects.
241
+ *
242
+ * @example
243
+ * const projects = {
244
+ * 'my-app': {
245
+ * type: 'app',
246
+ * data: { root: 'apps/my-app' }
247
+ * },
248
+ * 'my-lib': {
249
+ * type: 'lib',
250
+ * data: { root: 'libs/my-lib' }
251
+ * }
252
+ * };
253
+ *
254
+ * const tsConfigPaths = getTsConfigPaths(projects);
255
+ * console.log(tsConfigPaths);
256
+ * // Output:
257
+ * // ['apps/my-app/tsconfig.app.json', 'libs/my-lib/tsconfig.lib.json']
258
+ */
259
+ export declare const getNxTsConfigPaths: () => string[];
260
+ /**
261
+ * Initializes the project configuration with default values.
262
+ *
263
+ * @example
264
+ * const config = { type: ProjectType.APP, path: '/path/to/project', viteEnv: { mode: ViteMode.DEV } };
265
+ * const initializedConfig = initializeConfig(config);
266
+ */
267
+ export declare const initializeConfig: (ccfg: CommonProjectConfig, pcfg: ProjectConfig, localPkgJson: Record<string, any>) => {
268
+ viteCmd: ViteCommand;
269
+ cfg: ProjectConfigInitialized;
270
+ };
271
+ /**
272
+ * Handles merging configurations and logs any errors.
273
+ *
274
+ * @param {UserConfig} defaultConfig - The default configuration.
275
+ * @param {UserConfig} overrides - The overrides configuration.
276
+ * @returns {UserConfig} - The merged configuration.
277
+ */
278
+ export declare const mergeConfigs: (defaultConfig: UserConfig, overrides: UserConfig) => UserConfig;
279
+ /**
280
+ * Resolves glob patterns to actual package names found in package.json dependencies.
281
+ * This function is used to determine which packages should be treated as external
282
+ * in a Rollup or Vite build configuration.
283
+ *
284
+ * @param {string} path - The base path where package.json is located.
285
+ * @param {string | string[]} globs - A glob pattern or an array of glob patterns to match dependencies against.
286
+ * @returns {string[]} An array of package names that match the given glob patterns.
287
+ *
288
+ * @example
289
+ * // Example of using `getExternalDependencies` to find all dependencies starting with "my-lib" and "lodash"
290
+ * const projectPath = '/path/to/project';
291
+ * const globs = ['my-lib*', 'lodash'];
292
+ * const externalDependencies = getExternalDependencies(projectPath, globs);
293
+ * console.log(externalDependencies);
294
+ * // Output might be: ['my-lib/utils', 'my-lib/core', 'lodash']
295
+ */
296
+ export declare const getExternalDependencies: (path: string, globs?: string | string[]) => string[];
297
+ /**
298
+ * Generates a string of initials based on the input string,
299
+ * following certain rules:
300
+ * 1. A word is considered as a sequence of characters
301
+ * separated by hyphens.
302
+ * 2. If the string contains '@', any characters before
303
+ * and including the next '/' are ignored.
304
+ * 3. The first character of each word is taken to form
305
+ * the initials.
306
+ *
307
+ * @param {string} input - The input string from which to generate the initials.
308
+ * @returns {string} The initials formed by taking the first character
309
+ * of each word, after applying the specified rules.
310
+ *
311
+ * @example
312
+ * getInitials("player-script"); // returns "ps"
313
+ * getInitials("ssv-admin"); // returns "sa"
314
+ * getInitials("@nizza/customize-live"); // returns "cl"
315
+ */
316
+ export declare function getInitials(input: string): string;
317
+ /**
318
+ * Retrieves the Vite command details.
319
+ *
320
+ * @param {ViteMode} mode - The Vite mode.
321
+ * @returns {ViteCommand} - The command details.
322
+ *
323
+ * @example
324
+ * const command = getViteCommand(ViteMode.PROD);
325
+ * // Outputs: { stage: Stage.PROD, target: 'build', flags: {} }
326
+ */
327
+ export declare function getViteCommand(mode: ViteMode): ViteCommand;
328
+ /**
329
+ * Parses the command string to extract flags.
330
+ *
331
+ * @param {string | undefined} commandString - The command string.
332
+ * @returns {Record<string, string>} - The flags extracted from the command string.
333
+ *
334
+ * @example
335
+ * const flags = getViteCmdFlags('nx run core:build --source-maps');
336
+ * // Outputs: { 'source-maps: 'true' }
337
+ */
338
+ export declare function getViteCmdFlags(commandString: string | undefined): Record<string, string>;
339
+ /**
340
+ * Builds the configuration based on common and project-specific configurations.
341
+ *
342
+ * @param {CommonProjectConfig} commonConfig - The common configuration.
343
+ * @returns - Returns a function that accepts a project configuration and returns the Vite configuration.
344
+ */
345
+ export declare const createConfigBuilder: (commonConfig: CommonProjectConfig) => (projectConfig: ProjectConfig) => UserConfig;
346
+ export interface Execute {
347
+ function: (data?: string) => void;
348
+ listen: string;
349
+ observer: string;
350
+ }
351
+ export interface ThirdPartyCssInjectPlugin {
352
+ topExecutionPriority?: boolean;
353
+ execute?: Execute[];
354
+ }
355
+ /**
356
+ * Inject the CSS compiled with JS.
357
+ *
358
+ * @return {Plugin}
359
+ */
360
+ export declare function thirdPartyCssInjectPlugin({ topExecutionPriority, execute }?: ThirdPartyCssInjectPlugin | undefined): Plugin;
361
+ export declare function injectCssIntoShadowDom(): {
362
+ name: string;
363
+ configureServer(_server: ViteDevServer): void;
364
+ transform(src: string, id: string): void;
365
+ };
366
+
367
+ export {};
package/executors.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "executors": {
3
+ "environments": {
4
+ "implementation": "./dist/cjs/executors/environments/index.cjs",
5
+ "schema": "./dist/cjs/executors/environments/schema.json",
6
+ "description": "Configure project with custom environments"
7
+ },
8
+ "vtex-link": {
9
+ "implementation": "./dist/cjs/executors/vtex-link/index.cjs",
10
+ "schema": "./dist/cjs/executors/vtex-link/schema.json",
11
+ "description": "Links a package to a VTEX project."
12
+ },
13
+ "publish": {
14
+ "implementation": "./dist/cjs/executors/publish/index.cjs",
15
+ "schema": "./dist/cjs/executors/publish/schema.json",
16
+ "description": "publish executor"
17
+ },
18
+ "update-executors-file": {
19
+ "implementation": "./dist/cjs/executors/update-executors-file/index.cjs",
20
+ "schema": "./dist/cjs/executors/update-executors-file/schema.json",
21
+ "description": "update-executors-file executor"
22
+ },
23
+ "deploy": {
24
+ "implementation": "./dist/cjs/executors/deploy/index.cjs",
25
+ "schema": "./dist/cjs/executors/deploy/schema.json",
26
+ "description": "deploy executor"
27
+ }
28
+ }
29
+ }
package/package.json CHANGED
@@ -1,12 +1,58 @@
1
1
  {
2
2
  "name": "@nizza/devkit",
3
- "version": "0.1.0-alpha.1",
3
+ "version": "0.1.0-alpha.11",
4
+ "type": "module",
5
+ "main": "dist/cjs/index.cjs",
6
+ "module": "dist/esm/index.mjs",
4
7
  "source": "src/index.ts",
5
- "main": "dist/src/index.js",
6
- "types": "dist/src/index.d.ts",
8
+ "types": "dist/index.d.ts",
9
+ "exports": {
10
+ "./package.json": "./package.json",
11
+ ".": {
12
+ "import": "./dist/esm/index.mjs",
13
+ "require": "./dist/cjs/index.cjs"
14
+ },
15
+ "./import": {
16
+ "default": "./dist/esm/index.mjs"
17
+ },
18
+ "./require": {
19
+ "default": "./dist/cjs/index.cjs"
20
+ }
21
+ },
7
22
  "files": [
8
- "dist"
23
+ "dist",
24
+ "executors.json"
9
25
  ],
10
- "dependencies": {},
11
- "executors": "./executors.json"
26
+ "executors": "./executors.json",
27
+ "dependencies": {
28
+ "chalk": "^4",
29
+ "minimatch": "^9.0.3",
30
+ "mri": "^1.2.0",
31
+ "ramda": "^0.29.1",
32
+ "semver": "^7.5.4"
33
+ },
34
+ "devDependencies": {
35
+ "@rollup/plugin-commonjs": "^25.0.7",
36
+ "@rollup/plugin-json": "^6.0.1",
37
+ "@rollup/plugin-node-resolve": "^15.2.3",
38
+ "@types/semver": "^7.5.0",
39
+ "rollup": "^4.2.0",
40
+ "rollup-plugin-copy": "^3.5.0",
41
+ "rollup-plugin-delete": "^2.0.0",
42
+ "rollup-plugin-dts": "^6.1.0",
43
+ "rollup-plugin-dts-bundle-generator": "^1.4.0",
44
+ "rollup-plugin-swc3": "^0.10.3",
45
+ "rollup-plugin-ts": "^3.4.5"
46
+ },
47
+ "peerDependencies": {
48
+ "@nx/devkit": "17.0.2",
49
+ "@originjs/vite-plugin-commonjs": "^1.0.3",
50
+ "@rollup/plugin-graphql": "^2.0.4",
51
+ "@vitejs/plugin-react-swc": "^3.4.1",
52
+ "rollup-plugin-visualizer": "^5.9.2",
53
+ "vite": "^4.5.0",
54
+ "vite-plugin-css-injected-by-js": "^3.3.0",
55
+ "vite-plugin-dts": "^3.6.3",
56
+ "vite-tsconfig-paths": "^4.2.1"
57
+ }
12
58
  }