@ikas/component-cli 1.4.0-beta.22 → 1.4.0-beta.220

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 (204) hide show
  1. package/dist/build-tools.d.ts +37 -0
  2. package/dist/build-tools.d.ts.map +1 -0
  3. package/dist/build-tools.js +36 -0
  4. package/dist/build-tools.js.map +1 -0
  5. package/dist/commands/add-sections-to-page.d.ts +3 -0
  6. package/dist/commands/add-sections-to-page.d.ts.map +1 -0
  7. package/dist/commands/add-sections-to-page.js +39 -0
  8. package/dist/commands/add-sections-to-page.js.map +1 -0
  9. package/dist/commands/add.d.ts.map +1 -1
  10. package/dist/commands/add.js +11 -2
  11. package/dist/commands/add.js.map +1 -1
  12. package/dist/commands/build.d.ts.map +1 -1
  13. package/dist/commands/build.js +15 -167
  14. package/dist/commands/build.js.map +1 -1
  15. package/dist/commands/config-texts.d.ts +38 -0
  16. package/dist/commands/config-texts.d.ts.map +1 -0
  17. package/dist/commands/config-texts.js +186 -0
  18. package/dist/commands/config-texts.js.map +1 -0
  19. package/dist/commands/config.d.ts +45 -0
  20. package/dist/commands/config.d.ts.map +1 -1
  21. package/dist/commands/config.js +1148 -154
  22. package/dist/commands/config.js.map +1 -1
  23. package/dist/commands/create-design-tokens.d.ts +24 -0
  24. package/dist/commands/create-design-tokens.d.ts.map +1 -0
  25. package/dist/commands/create-design-tokens.js +388 -0
  26. package/dist/commands/create-design-tokens.js.map +1 -0
  27. package/dist/commands/create-global-variable.d.ts +3 -0
  28. package/dist/commands/create-global-variable.d.ts.map +1 -0
  29. package/dist/commands/create-global-variable.js +73 -0
  30. package/dist/commands/create-global-variable.js.map +1 -0
  31. package/dist/commands/create-page.d.ts +3 -0
  32. package/dist/commands/create-page.d.ts.map +1 -0
  33. package/dist/commands/create-page.js +31 -0
  34. package/dist/commands/create-page.js.map +1 -0
  35. package/dist/commands/delete-page.d.ts +3 -0
  36. package/dist/commands/delete-page.d.ts.map +1 -0
  37. package/dist/commands/delete-page.js +28 -0
  38. package/dist/commands/delete-page.js.map +1 -0
  39. package/dist/commands/delete-theme-globals.d.ts +4 -0
  40. package/dist/commands/delete-theme-globals.d.ts.map +1 -0
  41. package/dist/commands/delete-theme-globals.js +50 -0
  42. package/dist/commands/delete-theme-globals.js.map +1 -0
  43. package/dist/commands/dev.d.ts.map +1 -1
  44. package/dist/commands/dev.js +308 -39
  45. package/dist/commands/dev.js.map +1 -1
  46. package/dist/commands/enable-builtin-pages.d.ts +3 -0
  47. package/dist/commands/enable-builtin-pages.d.ts.map +1 -0
  48. package/dist/commands/enable-builtin-pages.js +28 -0
  49. package/dist/commands/enable-builtin-pages.js.map +1 -0
  50. package/dist/commands/get-component-props.d.ts +3 -0
  51. package/dist/commands/get-component-props.d.ts.map +1 -0
  52. package/dist/commands/get-component-props.js +32 -0
  53. package/dist/commands/get-component-props.js.map +1 -0
  54. package/dist/commands/get-page-by-type.d.ts +3 -0
  55. package/dist/commands/get-page-by-type.d.ts.map +1 -0
  56. package/dist/commands/get-page-by-type.js +25 -0
  57. package/dist/commands/get-page-by-type.js.map +1 -0
  58. package/dist/commands/get-section-values.d.ts +3 -0
  59. package/dist/commands/get-section-values.d.ts.map +1 -0
  60. package/dist/commands/get-section-values.js +39 -0
  61. package/dist/commands/get-section-values.js.map +1 -0
  62. package/dist/commands/list-builtin-pages.d.ts +3 -0
  63. package/dist/commands/list-builtin-pages.d.ts.map +1 -0
  64. package/dist/commands/list-builtin-pages.js +28 -0
  65. package/dist/commands/list-builtin-pages.js.map +1 -0
  66. package/dist/commands/list-entities.d.ts +3 -0
  67. package/dist/commands/list-entities.d.ts.map +1 -0
  68. package/dist/commands/list-entities.js +32 -0
  69. package/dist/commands/list-entities.js.map +1 -0
  70. package/dist/commands/list-page-sections.d.ts.map +1 -1
  71. package/dist/commands/list-page-sections.js +8 -2
  72. package/dist/commands/list-page-sections.js.map +1 -1
  73. package/dist/commands/list-theme-globals.d.ts +3 -0
  74. package/dist/commands/list-theme-globals.d.ts.map +1 -0
  75. package/dist/commands/list-theme-globals.js +22 -0
  76. package/dist/commands/list-theme-globals.js.map +1 -0
  77. package/dist/commands/list-translations.d.ts +3 -0
  78. package/dist/commands/list-translations.d.ts.map +1 -0
  79. package/dist/commands/list-translations.js +33 -0
  80. package/dist/commands/list-translations.js.map +1 -0
  81. package/dist/commands/move-page-section.d.ts +3 -0
  82. package/dist/commands/move-page-section.d.ts.map +1 -0
  83. package/dist/commands/move-page-section.js +62 -0
  84. package/dist/commands/move-page-section.js.map +1 -0
  85. package/dist/commands/publish-theme.d.ts +3 -0
  86. package/dist/commands/publish-theme.d.ts.map +1 -0
  87. package/dist/commands/publish-theme.js +29 -0
  88. package/dist/commands/publish-theme.js.map +1 -0
  89. package/dist/commands/publish.d.ts.map +1 -1
  90. package/dist/commands/publish.js +65 -3
  91. package/dist/commands/publish.js.map +1 -1
  92. package/dist/commands/remove-page-section.d.ts +3 -0
  93. package/dist/commands/remove-page-section.d.ts.map +1 -0
  94. package/dist/commands/remove-page-section.js +40 -0
  95. package/dist/commands/remove-page-section.js.map +1 -0
  96. package/dist/commands/search-products.d.ts +3 -0
  97. package/dist/commands/search-products.d.ts.map +1 -0
  98. package/dist/commands/search-products.js +40 -0
  99. package/dist/commands/search-products.js.map +1 -0
  100. package/dist/commands/translation-languages.d.ts +3 -0
  101. package/dist/commands/translation-languages.d.ts.map +1 -0
  102. package/dist/commands/translation-languages.js +43 -0
  103. package/dist/commands/translation-languages.js.map +1 -0
  104. package/dist/commands/update-builtin-page-prop.d.ts +3 -0
  105. package/dist/commands/update-builtin-page-prop.d.ts.map +1 -0
  106. package/dist/commands/update-builtin-page-prop.js +49 -0
  107. package/dist/commands/update-builtin-page-prop.js.map +1 -0
  108. package/dist/commands/update-global-variable.d.ts +3 -0
  109. package/dist/commands/update-global-variable.d.ts.map +1 -0
  110. package/dist/commands/update-global-variable.js +70 -0
  111. package/dist/commands/update-global-variable.js.map +1 -0
  112. package/dist/commands/update-page-sections.d.ts +3 -0
  113. package/dist/commands/update-page-sections.d.ts.map +1 -0
  114. package/dist/commands/update-page-sections.js +39 -0
  115. package/dist/commands/update-page-sections.js.map +1 -0
  116. package/dist/commands/update-section-prop.d.ts.map +1 -1
  117. package/dist/commands/update-section-prop.js +25 -8
  118. package/dist/commands/update-section-prop.js.map +1 -1
  119. package/dist/commands/update-translations.d.ts +3 -0
  120. package/dist/commands/update-translations.d.ts.map +1 -0
  121. package/dist/commands/update-translations.js +37 -0
  122. package/dist/commands/update-translations.js.map +1 -0
  123. package/dist/commands/upload-image.d.ts.map +1 -1
  124. package/dist/commands/upload-image.js +5 -46
  125. package/dist/commands/upload-image.js.map +1 -1
  126. package/dist/commands/upload-images.d.ts +3 -0
  127. package/dist/commands/upload-images.d.ts.map +1 -0
  128. package/dist/commands/upload-images.js +48 -0
  129. package/dist/commands/upload-images.js.map +1 -0
  130. package/dist/index.d.ts.map +1 -1
  131. package/dist/index.js +60 -1
  132. package/dist/index.js.map +1 -1
  133. package/dist/types.d.ts +77 -0
  134. package/dist/types.d.ts.map +1 -1
  135. package/dist/utils/archive-project.d.ts +50 -0
  136. package/dist/utils/archive-project.d.ts.map +1 -0
  137. package/dist/utils/archive-project.js +178 -0
  138. package/dist/utils/archive-project.js.map +1 -0
  139. package/dist/utils/compile.d.ts +17 -2
  140. package/dist/utils/compile.d.ts.map +1 -1
  141. package/dist/utils/compile.js +759 -117
  142. package/dist/utils/compile.js.map +1 -1
  143. package/dist/utils/component-helpers.d.ts +222 -4
  144. package/dist/utils/component-helpers.d.ts.map +1 -1
  145. package/dist/utils/component-helpers.js +558 -37
  146. package/dist/utils/component-helpers.js.map +1 -1
  147. package/dist/utils/css-import-resolver.d.ts +4 -1
  148. package/dist/utils/css-import-resolver.d.ts.map +1 -1
  149. package/dist/utils/css-import-resolver.js +9 -1
  150. package/dist/utils/css-import-resolver.js.map +1 -1
  151. package/dist/utils/dev-server-auth.d.ts +19 -0
  152. package/dist/utils/dev-server-auth.d.ts.map +1 -0
  153. package/dist/utils/dev-server-auth.js +60 -0
  154. package/dist/utils/dev-server-auth.js.map +1 -0
  155. package/dist/utils/editor-action-client.d.ts +4 -3
  156. package/dist/utils/editor-action-client.d.ts.map +1 -1
  157. package/dist/utils/editor-action-client.js +56 -19
  158. package/dist/utils/editor-action-client.js.map +1 -1
  159. package/dist/utils/esm-transform.d.ts +30 -0
  160. package/dist/utils/esm-transform.d.ts.map +1 -1
  161. package/dist/utils/esm-transform.js +169 -2
  162. package/dist/utils/esm-transform.js.map +1 -1
  163. package/dist/utils/find-component-for-file.d.ts +12 -0
  164. package/dist/utils/find-component-for-file.d.ts.map +1 -0
  165. package/dist/utils/find-component-for-file.js +24 -0
  166. package/dist/utils/find-component-for-file.js.map +1 -0
  167. package/dist/utils/forbid-deep-imports.d.ts +3 -0
  168. package/dist/utils/forbid-deep-imports.d.ts.map +1 -0
  169. package/dist/utils/forbid-deep-imports.js +54 -0
  170. package/dist/utils/forbid-deep-imports.js.map +1 -0
  171. package/dist/utils/forbid-external-packages.d.ts +26 -0
  172. package/dist/utils/forbid-external-packages.d.ts.map +1 -0
  173. package/dist/utils/forbid-external-packages.js +99 -0
  174. package/dist/utils/forbid-external-packages.js.map +1 -0
  175. package/dist/utils/i18n.d.ts +80 -0
  176. package/dist/utils/i18n.d.ts.map +1 -0
  177. package/dist/utils/i18n.js +265 -0
  178. package/dist/utils/i18n.js.map +1 -0
  179. package/dist/utils/load-image.d.ts +16 -0
  180. package/dist/utils/load-image.d.ts.map +1 -0
  181. package/dist/utils/load-image.js +50 -0
  182. package/dist/utils/load-image.js.map +1 -0
  183. package/dist/utils/storefront-t.d.ts +17 -0
  184. package/dist/utils/storefront-t.d.ts.map +1 -0
  185. package/dist/utils/storefront-t.js +186 -0
  186. package/dist/utils/storefront-t.js.map +1 -0
  187. package/dist/utils/vendor-storefront.d.ts +13 -0
  188. package/dist/utils/vendor-storefront.d.ts.map +1 -0
  189. package/dist/utils/vendor-storefront.js +91 -0
  190. package/dist/utils/vendor-storefront.js.map +1 -0
  191. package/dist/utils/websocket-server.d.ts +161 -7
  192. package/dist/utils/websocket-server.d.ts.map +1 -1
  193. package/dist/utils/websocket-server.js +324 -45
  194. package/dist/utils/websocket-server.js.map +1 -1
  195. package/package.json +19 -2
  196. package/templates/add/section.css +11 -0
  197. package/dist/commands/create.d.ts +0 -4
  198. package/dist/commands/create.d.ts.map +0 -1
  199. package/dist/commands/create.js +0 -228
  200. package/dist/commands/create.js.map +0 -1
  201. package/dist/commands/proxy.d.ts +0 -39
  202. package/dist/commands/proxy.d.ts.map +0 -1
  203. package/dist/commands/proxy.js +0 -210
  204. package/dist/commands/proxy.js.map +0 -1
@@ -0,0 +1,265 @@
1
+ import * as fs from "fs";
2
+ import * as path from "path";
3
+ export const I18N_DEFAULT_FILE = "default";
4
+ /** A key's segment: an identifier, so a dotted path stays plain. */
5
+ export const I18N_SEGMENT_PATTERN = /^[A-Za-z_][A-Za-z0-9_]*$/;
6
+ /** A language file's name: a language code (`en`, `pt-BR`); it becomes a path, so nothing else passes. */
7
+ const I18N_LOCALE_PATTERN = /^[a-z]{2,3}(-[A-Za-z0-9]{2,8})*$/;
8
+ const languageNames = new Intl.DisplayNames(["en"], {
9
+ type: "language",
10
+ fallback: "none",
11
+ });
12
+ /** Whether `code` names a real language (`en`, `pt-BR`; not `xx` or `en-XX`). */
13
+ export function isLanguageCode(code) {
14
+ if (!I18N_LOCALE_PATTERN.test(code))
15
+ return false;
16
+ try {
17
+ return languageNames.of(code) !== undefined;
18
+ }
19
+ catch {
20
+ return false;
21
+ }
22
+ }
23
+ /** The project's i18n folder, when its config names one. */
24
+ export function i18nDir(config, root = process.cwd()) {
25
+ return config.i18n ? path.resolve(root, config.i18n) : null;
26
+ }
27
+ /** The `{{param}}` names a text uses. */
28
+ export function textParams(text) {
29
+ return [
30
+ ...new Set([...text.matchAll(/{{([A-Za-z_][A-Za-z0-9_]*)}}/g)].map((match) => match[1])),
31
+ ];
32
+ }
33
+ const isTree = (value) => !!value && typeof value === "object" && !Array.isArray(value);
34
+ /** A tree's texts by dotted path; what is no text or group is reported, not kept. */
35
+ export function flattenI18n(tree, errors = [], prefix = "") {
36
+ return Object.entries(tree).reduce((texts, [segment, value]) => {
37
+ const key = prefix ? `${prefix}.${segment}` : segment;
38
+ if (!I18N_SEGMENT_PATTERN.test(segment))
39
+ errors.push(`"${key}": "${segment}" must be an identifier (letters, digits, _; not starting with a digit).`);
40
+ else if (isTree(value))
41
+ Object.assign(texts, flattenI18n(value, errors, key));
42
+ else if (typeof value !== "string" || !value.trim())
43
+ errors.push(`"${key}" needs a text or a group.`);
44
+ else
45
+ texts[key] = value;
46
+ return texts;
47
+ }, {});
48
+ }
49
+ /** Texts by dotted path back into a tree, keys sorted so a written file is stable. */
50
+ export function unflattenI18n(texts) {
51
+ const tree = {};
52
+ Object.keys(texts)
53
+ .sort()
54
+ .forEach((key) => {
55
+ const segments = key.split(".");
56
+ const parent = segments
57
+ .slice(0, -1)
58
+ .reduce((node, segment) => (node[segment] ??= {}), tree);
59
+ parent[segments[segments.length - 1]] = texts[key];
60
+ });
61
+ return tree;
62
+ }
63
+ /**
64
+ * What is wrong with a language's texts against the base: a key the base lacks, or one whose `{{param}}`s differ
65
+ * from the base text's (`t()` passes the base's). Returns the valid texts too.
66
+ */
67
+ export function checkLocaleTexts(base, texts, locale) {
68
+ const errors = [];
69
+ const valid = {};
70
+ Object.entries(texts).forEach(([key, text]) => {
71
+ if (!(key in base))
72
+ return errors.push(`${locale}.json "${key}": not in ${I18N_DEFAULT_FILE}.json.`);
73
+ const expected = textParams(base[key]).sort().join(", ");
74
+ const actual = textParams(text).sort().join(", ");
75
+ if (actual !== expected)
76
+ return errors.push(`${locale}.json "${key}": uses {{${actual || "-"}}}, the base text {{${expected || "-"}}}.`);
77
+ valid[key] = text;
78
+ });
79
+ return { valid, errors };
80
+ }
81
+ /**
82
+ * Reads the i18n folder. A file that is no valid JSON is reported and left out (`unreadable`: the caller keeps what
83
+ * it had); texts that break the rules are reported and left out, so the editor and the store get only valid ones.
84
+ */
85
+ export function readI18n(dir) {
86
+ const errors = [];
87
+ const unreadable = [];
88
+ const read = (file) => {
89
+ try {
90
+ const value = JSON.parse(fs.readFileSync(path.join(dir, file), "utf-8"));
91
+ if (isTree(value))
92
+ return value;
93
+ errors.push(`${file}: must hold an object of texts and groups.`);
94
+ }
95
+ catch (e) {
96
+ errors.push(`${file}: ${e.message}`);
97
+ }
98
+ unreadable.push(file);
99
+ return null;
100
+ };
101
+ const files = fs.existsSync(dir)
102
+ ? fs.readdirSync(dir).filter((file) => file.endsWith(".json"))
103
+ : [];
104
+ const defaultFile = `${I18N_DEFAULT_FILE}.json`;
105
+ if (!files.includes(defaultFile) && files.length > 0)
106
+ errors.push(`${defaultFile} is missing: the languages' texts need base texts.`);
107
+ const base = files.includes(defaultFile)
108
+ ? flattenI18n(read(defaultFile) ?? {}, errors)
109
+ : {};
110
+ const locales = {};
111
+ files
112
+ .filter((file) => file !== defaultFile)
113
+ .forEach((file) => {
114
+ const locale = file.slice(0, -".json".length);
115
+ if (!isLanguageCode(locale))
116
+ return errors.push(`${file}: the name must be a language code (en, de, pt-BR).`);
117
+ const tree = read(file);
118
+ if (!tree)
119
+ return;
120
+ const checked = checkLocaleTexts(base, flattenI18n(tree, errors), locale);
121
+ errors.push(...checked.errors);
122
+ locales[locale] = checked.valid;
123
+ });
124
+ return { base, locales, errors, unreadable };
125
+ }
126
+ /** The types file written next to the texts: what `import { t } from "@ikas/bp-storefront"` takes. */
127
+ export const I18N_TYPES_FILE = "index.d.ts";
128
+ const AUTO_GENERATED = `// This file is auto-generated from ${I18N_DEFAULT_FILE}.json — do not edit manually.`;
129
+ /**
130
+ * The generated `<dir>/index.d.ts`: types only. It fills `UiTexts` of `@ikas/bp-storefront` with the base texts, so
131
+ * its `t` takes only the project's keys and their `{{param}}`s; the build binds that `t` to the project's texts.
132
+ */
133
+ export function generateI18nTypes(base) {
134
+ const entries = Object.keys(base)
135
+ .sort()
136
+ .map((key) => ` ${JSON.stringify(key)}: ${JSON.stringify(base[key])};`)
137
+ .join("\n");
138
+ return `${AUTO_GENERATED}
139
+ // Types the keys and {{params}} of \`import { t } from "@ikas/bp-storefront"\`.
140
+ declare module "@ikas/bp-storefront" {
141
+ interface UiTexts {
142
+ ${entries}
143
+ }
144
+ }
145
+
146
+ export {};
147
+ `;
148
+ }
149
+ /**
150
+ * The `t` the build gives for `import { t } from "@ikas/bp-storefront"` (never written to the project): the store
151
+ * language's text of the project's `key`, else its base text, else the key; its `{{param}}`s filled in one pass.
152
+ */
153
+ export function generateI18nRuntime(projectId, base) {
154
+ return `import { I18n } from "@ikas/bp-storefront";
155
+ const texts = ${JSON.stringify(base)};
156
+ export function t(key, params) {
157
+ const path = ${JSON.stringify(`cc.${projectId}.`)} + key;
158
+ const text = I18n.translate(path);
159
+ const values = params || {};
160
+ // In one pass: a value holding {{...}} is put in as it is
161
+ return (text === path ? (texts[key] ?? key) : text).replace(/{{([A-Za-z_][A-Za-z0-9_]*)}}/g, (match, name) =>
162
+ name in values ? String(values[name]) : match,
163
+ );
164
+ }
165
+ `;
166
+ }
167
+ /** Writes a file when its content changed: an unchanged write would wake the watcher for nothing. */
168
+ export function writeIfChanged(filePath, content) {
169
+ try {
170
+ if (fs.readFileSync(filePath, "utf-8") === content)
171
+ return false;
172
+ }
173
+ catch {
174
+ // Not there yet
175
+ }
176
+ fs.mkdirSync(path.dirname(filePath), { recursive: true });
177
+ fs.writeFileSync(filePath, content);
178
+ return true;
179
+ }
180
+ /** Writes a language's texts (`default` for the base), sorted; no texts left removes a language's file. */
181
+ export function writeI18nFile(dir, locale, texts) {
182
+ if (locale !== I18N_DEFAULT_FILE && !isLanguageCode(locale))
183
+ throw new Error(`"${locale}" is not a language code.`);
184
+ const filePath = path.join(dir, `${locale}.json`);
185
+ if (locale !== I18N_DEFAULT_FILE && Object.keys(texts).length === 0) {
186
+ if (!fs.existsSync(filePath))
187
+ return false;
188
+ fs.rmSync(filePath);
189
+ return true;
190
+ }
191
+ return writeIfChanged(filePath, JSON.stringify(unflattenI18n(texts), null, 2) + "\n");
192
+ }
193
+ /**
194
+ * Reads the project's texts for the editor and writes the generated `index.d.ts`; `null` when the config names no
195
+ * folder. Problems are returned to be shown; a file that cannot be read keeps `previous`'s texts.
196
+ */
197
+ export function loadProjectI18n(config, previous, root = process.cwd()) {
198
+ const dir = i18nDir(config, root);
199
+ if (!config.projectId)
200
+ return { data: undefined, errors: [] };
201
+ // No folder: no texts (the editor drops the ones it had)
202
+ if (!dir)
203
+ return {
204
+ data: { projectId: config.projectId, base: {}, locales: {} },
205
+ errors: [],
206
+ };
207
+ const read = readI18n(dir);
208
+ const keep = (file) => read.unreadable.includes(file);
209
+ // The languages are checked against the base: without it, everything stays as it was
210
+ if (keep(`${I18N_DEFAULT_FILE}.json`))
211
+ return { data: previous, errors: read.errors };
212
+ const base = read.base;
213
+ const locales = Object.fromEntries(Object.entries(read.locales).map(([locale, texts]) => [
214
+ locale,
215
+ unflattenI18n(texts),
216
+ ]));
217
+ Object.entries(previous?.locales ?? {}).forEach(([locale, tree]) => {
218
+ if (keep(`${locale}.json`))
219
+ locales[locale] = tree;
220
+ });
221
+ writeIfChanged(path.join(dir, I18N_TYPES_FILE), generateI18nTypes(base));
222
+ // The module earlier versions generated: its t now comes from the build (see \`storefrontTPlugin\`)
223
+ const legacyModule = path.join(dir, "index.ts");
224
+ if (fs.existsSync(legacyModule) &&
225
+ fs.readFileSync(legacyModule, "utf-8").startsWith(AUTO_GENERATED))
226
+ fs.rmSync(legacyModule);
227
+ return {
228
+ data: {
229
+ projectId: config.projectId,
230
+ base: unflattenI18n(base),
231
+ // Sorted: a kept file must not change the order, and with it the texts' hash
232
+ locales: Object.fromEntries(Object.keys(locales)
233
+ .sort()
234
+ .map((locale) => [locale, locales[locale]])),
235
+ },
236
+ errors: read.errors,
237
+ };
238
+ }
239
+ /**
240
+ * Writes the texts the editor saved (the base ones and the sent languages', nested) to the i18n folder: only a file
241
+ * whose texts changed is rewritten, a language with no texts left loses its file. Refused whole when one breaks the
242
+ * rules, so the files never hold what the editor would not show.
243
+ */
244
+ export function writeEditorI18n(config, texts, root = process.cwd()) {
245
+ const dir = i18nDir(config, root);
246
+ if (!dir)
247
+ throw new Error("The project has no UI texts folder (config i18n).");
248
+ const errors = [];
249
+ const base = flattenI18n(texts.base, errors);
250
+ const locales = Object.entries(texts.locales).map(([locale, tree]) => {
251
+ if (!isLanguageCode(locale))
252
+ errors.push(`"${locale}" is not a language code.`);
253
+ const checked = checkLocaleTexts(base, flattenI18n(tree, errors), locale);
254
+ errors.push(...checked.errors);
255
+ return [locale, checked.valid];
256
+ });
257
+ if (errors.length)
258
+ throw new Error(errors.join(" "));
259
+ const written = [
260
+ ...(writeI18nFile(dir, I18N_DEFAULT_FILE, base) ? [I18N_DEFAULT_FILE] : []),
261
+ ...locales.flatMap(([locale, localeTexts]) => writeI18nFile(dir, locale, localeTexts) ? [locale] : []),
262
+ ];
263
+ return written;
264
+ }
265
+ //# sourceMappingURL=i18n.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"i18n.js","sourceRoot":"","sources":["../../src/utils/i18n.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAkB7B,MAAM,CAAC,MAAM,iBAAiB,GAAG,SAAS,CAAC;AAC3C,oEAAoE;AACpE,MAAM,CAAC,MAAM,oBAAoB,GAAG,0BAA0B,CAAC;AAC/D,0GAA0G;AAC1G,MAAM,mBAAmB,GAAG,kCAAkC,CAAC;AAE/D,MAAM,aAAa,GAAG,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE;IAClD,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE,MAAM;CACjB,CAAC,CAAC;AAEH,iFAAiF;AACjF,MAAM,UAAU,cAAc,CAAC,IAAY;IACzC,IAAI,CAAC,mBAAmB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AC,CAAC,CAAC,MAAM,EAAE,IAAI,CAAC,EAAE,EAAE;QACnE,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC;YACzB,MAAM,CAAC,IAAI,CAAC,IAAI,MAAM,2BAA2B,CAAC,CAAC;QACrD,MAAM,OAAO,GAAG,gBAAgB,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,CAAC,CAAC;QAC1E,MAAM,CAAC,IAAI,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;QAC/B,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAU,CAAC;IAC1C,CAAC,CAAC,CAAC;IACH,IAAI,MAAM,CAAC,MAAM;QAAE,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IACrD,MAAM,OAAO,GAAG;QACd,GAAG,CAAC,aAAa,CAAC,GAAG,EAAE,iBAAiB,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC3E,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,WAAW,CAAC,EAAE,EAAE,CAC3C,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CACxD;KACF,CAAC;IACF,OAAO,OAAO,CAAC;AACjB,CAAC"}
@@ -0,0 +1,16 @@
1
+ export declare const VALID_IMAGE_TYPES: string[];
2
+ export interface ImageSource {
3
+ file?: string;
4
+ url?: string;
5
+ }
6
+ export interface LoadedImage {
7
+ base64: string;
8
+ mimeType: string;
9
+ fileName: string;
10
+ }
11
+ /**
12
+ * Read an image from a local file path or URL and return its base64 (raw, no
13
+ * data: prefix), mime type, and a file name. Validates type and the 10MB limit.
14
+ */
15
+ export declare function loadImageSource(src: ImageSource): Promise<LoadedImage>;
16
+ //# sourceMappingURL=load-image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-image.d.ts","sourceRoot":"","sources":["../../src/utils/load-image.ts"],"names":[],"mappings":"AAWA,eAAO,MAAM,iBAAiB,UAA6B,CAAC;AAG5D,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED;;;GAGG;AACH,wBAAsB,eAAe,CAAC,GAAG,EAAE,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC,CAsC5E"}
@@ -0,0 +1,50 @@
1
+ import { readFile } from "node:fs/promises";
2
+ import { basename, extname } from "node:path";
3
+ const MIME_BY_EXT = {
4
+ ".png": "image/png",
5
+ ".jpg": "image/jpeg",
6
+ ".jpeg": "image/jpeg",
7
+ ".webp": "image/webp",
8
+ ".gif": "image/gif",
9
+ };
10
+ export const VALID_IMAGE_TYPES = Object.values(MIME_BY_EXT);
11
+ const MAX_SIZE_BYTES = 10 * 1024 * 1024; // 10MB, mirrors the editor's IMAGE_UPLOAD_LIMIT_SIZE
12
+ /**
13
+ * Read an image from a local file path or URL and return its base64 (raw, no
14
+ * data: prefix), mime type, and a file name. Validates type and the 10MB limit.
15
+ */
16
+ export async function loadImageSource(src) {
17
+ if (src.file && src.url) {
18
+ throw new Error("Provide only one of file or url, not both");
19
+ }
20
+ if (src.file) {
21
+ const buffer = await readFile(src.file);
22
+ const ext = extname(src.file).toLowerCase();
23
+ const mimeType = MIME_BY_EXT[ext];
24
+ if (!mimeType) {
25
+ throw new Error(`Unsupported image extension "${ext || "(none)"}" for ${src.file}. Supported: ${Object.keys(MIME_BY_EXT).join(", ")}`);
26
+ }
27
+ if (buffer.byteLength > MAX_SIZE_BYTES) {
28
+ throw new Error(`${src.file} is ${(buffer.byteLength / 1024 / 1024).toFixed(1)}MB; the limit is 10MB`);
29
+ }
30
+ return { base64: buffer.toString("base64"), mimeType, fileName: basename(src.file) };
31
+ }
32
+ if (src.url) {
33
+ const res = await fetch(src.url);
34
+ if (!res.ok) {
35
+ throw new Error(`Failed to fetch ${src.url}: ${res.status} ${res.statusText}`);
36
+ }
37
+ const mimeType = (res.headers.get("content-type") || "").split(";")[0].trim();
38
+ if (!VALID_IMAGE_TYPES.includes(mimeType)) {
39
+ throw new Error(`${src.url} returned content-type "${mimeType || "(none)"}". Supported: ${VALID_IMAGE_TYPES.join(", ")}`);
40
+ }
41
+ const buffer = Buffer.from(await res.arrayBuffer());
42
+ if (buffer.byteLength > MAX_SIZE_BYTES) {
43
+ throw new Error(`${src.url} is ${(buffer.byteLength / 1024 / 1024).toFixed(1)}MB; the limit is 10MB`);
44
+ }
45
+ const urlName = basename(new URL(src.url).pathname) || "image";
46
+ return { base64: buffer.toString("base64"), mimeType, fileName: urlName };
47
+ }
48
+ throw new Error("Provide a file path or url");
49
+ }
50
+ //# sourceMappingURL=load-image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"load-image.js","sourceRoot":"","sources":["../../src/utils/load-image.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAE9C,MAAM,WAAW,GAA2B;IAC1C,MAAM,EAAE,WAAW;IACnB,MAAM,EAAE,YAAY;IACpB,OAAO,EAAE,YAAY;IACrB,OAAO,EAAE,YAAY;IACrB,MAAM,EAAE,WAAW;CACpB,CAAC;AAEF,MAAM,CAAC,MAAM,iBAAiB,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;AAC5D,MAAM,cAAc,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC,CAAC,qDAAqD;AAa9F;;;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with `t` imported from the project's UI texts module (`i18nModule`) in place of `@ikas/bp-storefront`,
5
+ * whose shared runtime has no `t`: each project reads its own texts. The other imports stay as they are, on the
6
+ * same lines. `null`: nothing to change. Throws on a form that would read `t` from the shared runtime.
7
+ */
8
+ export declare function rewriteStorefrontT(ts: typeof TS, source: string, fileName: string, i18nModule: string | null): string | null;
9
+ /** The module the build gives `t` from: the project's texts and their `t`, made from its i18n files. */
10
+ export declare const UI_TEXTS_MODULE = "@ikas/component-utils/ui-texts";
11
+ /**
12
+ * Binds `import { t } from "@ikas/bp-storefront"` to a `t` reading the project's own UI texts, made from its i18n
13
+ * files (`UI_TEXTS_MODULE`, never written to the project): the storefront runtime is shared by every project on a
14
+ * store, so a `t` there could not tell whose text a key is. The generated `index.d.ts` types that `t`.
15
+ */
16
+ export declare function storefrontTPlugin(root?: string): Plugin;
17
+ //# sourceMappingURL=storefront-t.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storefront-t.d.ts","sourceRoot":"","sources":["../../src/utils/storefront-t.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAU,MAAM,EAAE,MAAM,SAAS,CAAC;AAI9C,OAAO,KAAK,KAAK,EAAE,MAAM,YAAY,CAAC;AAuCtC;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,EAAE,EAAE,OAAO,EAAE,EACb,MAAM,EAAE,MAAM,EACd,QAAQ,EAAE,MAAM,EAChB,UAAU,EAAE,MAAM,GAAG,IAAI,GACxB,MAAM,GAAG,IAAI,CAyIf;AAED,wGAAwG;AAExG,eAAO,MAAM,eAAe,mCAAmC,CAAC;AAEhE;;;;GAIG;AACH,wBAAgB,iBAAiB,CAAC,IAAI,SAAgB,GAAG,MAAM,CAsD9D"}
@@ -0,0 +1,186 @@
1
+ import * as fs from "fs";
2
+ import { createRequire } from "module";
3
+ import * as path from "path";
4
+ import { generateI18nRuntime, I18N_DEFAULT_FILE, i18nDir, readI18n, } from "./i18n.js";
5
+ const STOREFRONT = "@ikas/bp-storefront";
6
+ const SOURCE_FILE = /\.[cm]?[jt]sx?$/;
7
+ const LOADERS = {
8
+ ".ts": "ts",
9
+ ".mts": "ts",
10
+ ".cts": "ts",
11
+ ".tsx": "tsx",
12
+ ".jsx": "jsx",
13
+ };
14
+ /** The project's own TypeScript (the build type-checks with it), else one the CLI can reach. */
15
+ function loadTypeScript(root) {
16
+ const from = [path.join(root, "package.json"), import.meta.url];
17
+ const found = from.reduce((ts, base) => {
18
+ if (ts)
19
+ return ts;
20
+ try {
21
+ return createRequire(base)("typescript");
22
+ }
23
+ catch {
24
+ return undefined;
25
+ }
26
+ }, undefined);
27
+ if (!found)
28
+ throw new Error(`import { t } from "${STOREFRONT}" needs the project's TypeScript: install it (npm i -D typescript).`);
29
+ return found;
30
+ }
31
+ /**
32
+ * `source` with `t` imported from the project's UI texts module (`i18nModule`) in place of `@ikas/bp-storefront`,
33
+ * whose shared runtime has no `t`: each project reads its own texts. The other imports stay as they are, on the
34
+ * same lines. `null`: nothing to change. Throws on a form that would read `t` from the shared runtime.
35
+ */
36
+ export function rewriteStorefrontT(ts, source, fileName, i18nModule) {
37
+ if (!source.includes(STOREFRONT))
38
+ return null;
39
+ const file = ts.createSourceFile(fileName, source, ts.ScriptTarget.Latest, true);
40
+ const isStorefront = (specifier) => !!specifier &&
41
+ ts.isStringLiteral(specifier) &&
42
+ specifier.text === STOREFRONT;
43
+ const fail = (node, problem) => {
44
+ const { line } = file.getLineAndCharacterOfPosition(node.getStart(file));
45
+ throw new Error(`${path.basename(fileName)}:${line + 1}: ${problem} Import it by name: import { t } from "${STOREFRONT}".`);
46
+ };
47
+ const needTexts = (node) => {
48
+ if (!i18nModule)
49
+ fail(node, `t reads the project's UI texts, and it has none yet: add one with \`ikas-component config set-text\`.`);
50
+ };
51
+ // A namespace import's `t` would be read from the shared runtime: `S.t`, `S["t"]`, `const { t } = S`
52
+ const namespaces = new Set();
53
+ const edits = [];
54
+ file.statements.forEach((statement) => {
55
+ if (ts.isExportDeclaration(statement) &&
56
+ isStorefront(statement.moduleSpecifier) &&
57
+ !statement.isTypeOnly) {
58
+ const clause = statement.exportClause;
59
+ const named = clause && ts.isNamedExports(clause)
60
+ ? clause.elements.some((e) => !e.isTypeOnly && (e.propertyName ?? e.name).text === "t")
61
+ : !clause && !!i18nModule;
62
+ if (named)
63
+ fail(statement, `t cannot be re-exported from "${STOREFRONT}" (it has no t at runtime).`);
64
+ return;
65
+ }
66
+ if (!ts.isImportDeclaration(statement) ||
67
+ !isStorefront(statement.moduleSpecifier))
68
+ return;
69
+ const clause = statement.importClause;
70
+ if (!clause || clause.isTypeOnly || !clause.namedBindings)
71
+ return;
72
+ const bindings = clause.namedBindings;
73
+ if (ts.isNamespaceImport(bindings)) {
74
+ namespaces.add(bindings.name.text);
75
+ return;
76
+ }
77
+ const tImports = bindings.elements.filter((e) => !e.isTypeOnly && (e.propertyName ?? e.name).text === "t");
78
+ if (!tImports.length)
79
+ return;
80
+ needTexts(statement);
81
+ const rest = bindings.elements
82
+ .filter((e) => !tImports.includes(e))
83
+ .map((e) => e.getText(file));
84
+ const head = [
85
+ clause.name?.text,
86
+ rest.length ? `{ ${rest.join(", ")} }` : undefined,
87
+ ].filter(Boolean);
88
+ const kept = head.length
89
+ ? `import ${head.join(", ")} from "${STOREFRONT}"; `
90
+ : "";
91
+ const names = tImports
92
+ .map((e) => (e.name.text === "t" ? "t" : `t as ${e.name.text}`))
93
+ .join(", ");
94
+ const original = source.slice(statement.getStart(file), statement.getEnd());
95
+ edits.push({
96
+ start: statement.getStart(file),
97
+ end: statement.getEnd(),
98
+ // On the import's own lines: the code below keeps its line numbers
99
+ text: `${kept}import { ${names} } from ${JSON.stringify(i18nModule)};${"\n".repeat(original.split("\n").length - 1)}`,
100
+ });
101
+ });
102
+ if (namespaces.size) {
103
+ const visit = (node) => {
104
+ const isNamespace = (e) => ts.isIdentifier(e) && namespaces.has(e.text);
105
+ if (ts.isPropertyAccessExpression(node) &&
106
+ isNamespace(node.expression) &&
107
+ node.name.text === "t")
108
+ fail(node, `t is not read through a namespace import of "${STOREFRONT}".`);
109
+ if (ts.isElementAccessExpression(node) &&
110
+ isNamespace(node.expression) &&
111
+ ts.isStringLiteralLike(node.argumentExpression) &&
112
+ node.argumentExpression.text === "t")
113
+ fail(node, `t is not read through a namespace import of "${STOREFRONT}".`);
114
+ if (ts.isVariableDeclaration(node) &&
115
+ node.initializer &&
116
+ isNamespace(node.initializer) &&
117
+ ts.isObjectBindingPattern(node.name) &&
118
+ node.name.elements.some((e) => (e.propertyName ?? e.name).text === "t"))
119
+ fail(node, `t is not read through a namespace import of "${STOREFRONT}".`);
120
+ ts.forEachChild(node, visit);
121
+ };
122
+ visit(file);
123
+ }
124
+ if (!edits.length)
125
+ return null;
126
+ return edits
127
+ .sort((a, b) => b.start - a.start)
128
+ .reduce((text, edit) => text.slice(0, edit.start) + edit.text + text.slice(edit.end), source);
129
+ }
130
+ /** The module the build gives `t` from: the project's texts and their `t`, made from its i18n files. */
131
+ // Under the CLI's own virtual package, which the package rules allow
132
+ export const UI_TEXTS_MODULE = "@ikas/component-utils/ui-texts";
133
+ /**
134
+ * Binds `import { t } from "@ikas/bp-storefront"` to a `t` reading the project's own UI texts, made from its i18n
135
+ * files (`UI_TEXTS_MODULE`, never written to the project): the storefront runtime is shared by every project on a
136
+ * store, so a `t` there could not tell whose text a key is. The generated `index.d.ts` types that `t`.
137
+ */
138
+ export function storefrontTPlugin(root = process.cwd()) {
139
+ return {
140
+ name: "ikas-storefront-t",
141
+ setup(build) {
142
+ let config;
143
+ try {
144
+ config = JSON.parse(fs.readFileSync(path.join(root, "ikas.config.json"), "utf-8"));
145
+ }
146
+ catch {
147
+ // No project config: nothing to bind
148
+ }
149
+ const dir = config ? i18nDir(config, root) : null;
150
+ const hasTexts = !!dir && fs.existsSync(path.join(dir, `${I18N_DEFAULT_FILE}.json`));
151
+ build.onResolve({ filter: /^@ikas\/component-utils\/ui-texts$/ }, (args) => ({
152
+ path: args.path,
153
+ namespace: "ikas-ui-texts",
154
+ }));
155
+ build.onLoad({ filter: /.*/, namespace: "ikas-ui-texts" }, () => ({
156
+ // Read at each build: a changed base text (its `index.d.ts` rewritten) recompiles in dev
157
+ contents: generateI18nRuntime(config.projectId, readI18n(dir).base),
158
+ loader: "js",
159
+ resolveDir: root,
160
+ }));
161
+ let ts;
162
+ build.onLoad({ filter: SOURCE_FILE }, (args) => {
163
+ if (args.path.split(path.sep).includes("node_modules"))
164
+ return undefined;
165
+ const source = fs.readFileSync(args.path, "utf-8");
166
+ if (!source.includes(STOREFRONT))
167
+ return undefined;
168
+ try {
169
+ ts ??= loadTypeScript(root);
170
+ const contents = rewriteStorefrontT(ts, source, args.path, hasTexts ? UI_TEXTS_MODULE : null);
171
+ if (contents === null)
172
+ return undefined;
173
+ return {
174
+ contents,
175
+ loader: LOADERS[path.extname(args.path)] ?? "js",
176
+ resolveDir: path.dirname(args.path),
177
+ };
178
+ }
179
+ catch (e) {
180
+ return { errors: [{ text: e.message }] };
181
+ }
182
+ });
183
+ },
184
+ };
185
+ }
186
+ //# sourceMappingURL=storefront-t.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"storefront-t.js","sourceRoot":"","sources":["../../src/utils/storefront-t.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,IAAI,CAAC;AACzB,OAAO,EAAE,aAAa,EAAE,MAAM,QAAQ,CAAC;AACvC,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAI7B,OAAO,EACL,mBAAmB,EACnB,iBAAiB,EACjB,OAAO,EACP,QAAQ,GACT,MAAM,WAAW,CAAC;AAEnB,MAAM,UAAU,GAAG,qBAAqB,CAAC;AACzC,MAAM,WAAW,GAAG,iBAAiB,CAAC;AAEtC,MAAM,OAAO,GAA2B;IACtC,KAAK,EAAE,IAAI;IACX,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,IAAI;IACZ,MAAM,EAAE,KAAK;IACb,MAAM,EAAE,KAAK;CACd,CAAC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,EAAE,MAAM,EAAE,WAAW,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;gBAC7C,IAAI,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,cAAc,CAAC;oBACpD,OAAO,SAAS,CAAC;gBACnB,MAAM,MAAM,GAAG,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBACnD,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAAC;oBAAE,OAAO,SAAS,CAAC;gBACnD,IAAI,CAAC;oBACH,EAAE,KAAK,cAAc,CAAC,IAAI,CAAC,CAAC;oBAC5B,MAAM,QAAQ,GAAG,kBAAkB,CACjC,EAAE,EACF,MAAM,EACN,IAAI,CAAC,IAAI,EACT,QAAQ,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,IAAI,CAClC,CAAC;oBACF,IAAI,QAAQ,KAAK,IAAI;wBAAE,OAAO,SAAS,CAAC;oBACxC,OAAO;wBACL,QAAQ;wBACR,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI;wBAChD,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;qBACpC,CAAC;gBACJ,CAAC;gBAAC,OAAO,CAAC,EAAE,CAAC;oBACX,OAAO,EAAE,MAAM,EAAE,CAAC,EAAE,IAAI,EAAG,CAAW,CAAC,OAAO,EAAE,CAAC,EAAE,CAAC;gBACtD,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -0,0 +1,13 @@
1
+ import type { Plugin } from "esbuild";
2
+ export declare function isVendoredDependencyFile(file: string): boolean;
3
+ /**
4
+ * Bundle the storefront SDK into the component artifact.
5
+ *
6
+ * Deep imports stay forbidden for *component* source — the public contract is still "import only
7
+ * from the package root", and a component reaching into `/src/...` is still a bug worth failing
8
+ * on. But the SDK's own modules deep-import each other constantly (97 lazy `import()` calls into
9
+ * `@ikas/bp-storefront-api/src/__api/...` alone), and those are internal business. So the rule is
10
+ * keyed on who is importing, not on what is imported.
11
+ */
12
+ export declare function vendorStorefrontPlugin(): Plugin;
13
+ //# sourceMappingURL=vendor-storefront.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vendor-storefront.d.ts","sourceRoot":"","sources":["../../src/utils/vendor-storefront.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAqCtC,wBAAgB,wBAAwB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAK9D;AAqBD;;;;;;;;GAQG;AACH,wBAAgB,sBAAsB,IAAI,MAAM,CA+B/C"}