@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.
- package/dist/build-tools.d.ts +37 -0
- package/dist/build-tools.d.ts.map +1 -0
- package/dist/build-tools.js +36 -0
- package/dist/build-tools.js.map +1 -0
- package/dist/commands/add-sections-to-page.d.ts +3 -0
- package/dist/commands/add-sections-to-page.d.ts.map +1 -0
- package/dist/commands/add-sections-to-page.js +39 -0
- package/dist/commands/add-sections-to-page.js.map +1 -0
- package/dist/commands/add.d.ts.map +1 -1
- package/dist/commands/add.js +11 -2
- package/dist/commands/add.js.map +1 -1
- package/dist/commands/build.d.ts.map +1 -1
- package/dist/commands/build.js +15 -167
- package/dist/commands/build.js.map +1 -1
- package/dist/commands/config-texts.d.ts +38 -0
- package/dist/commands/config-texts.d.ts.map +1 -0
- package/dist/commands/config-texts.js +186 -0
- package/dist/commands/config-texts.js.map +1 -0
- package/dist/commands/config.d.ts +45 -0
- package/dist/commands/config.d.ts.map +1 -1
- package/dist/commands/config.js +1148 -154
- package/dist/commands/config.js.map +1 -1
- package/dist/commands/create-design-tokens.d.ts +24 -0
- package/dist/commands/create-design-tokens.d.ts.map +1 -0
- package/dist/commands/create-design-tokens.js +388 -0
- package/dist/commands/create-design-tokens.js.map +1 -0
- package/dist/commands/create-global-variable.d.ts +3 -0
- package/dist/commands/create-global-variable.d.ts.map +1 -0
- package/dist/commands/create-global-variable.js +73 -0
- package/dist/commands/create-global-variable.js.map +1 -0
- package/dist/commands/create-page.d.ts +3 -0
- package/dist/commands/create-page.d.ts.map +1 -0
- package/dist/commands/create-page.js +31 -0
- package/dist/commands/create-page.js.map +1 -0
- package/dist/commands/delete-page.d.ts +3 -0
- package/dist/commands/delete-page.d.ts.map +1 -0
- package/dist/commands/delete-page.js +28 -0
- package/dist/commands/delete-page.js.map +1 -0
- package/dist/commands/delete-theme-globals.d.ts +4 -0
- package/dist/commands/delete-theme-globals.d.ts.map +1 -0
- package/dist/commands/delete-theme-globals.js +50 -0
- package/dist/commands/delete-theme-globals.js.map +1 -0
- package/dist/commands/dev.d.ts.map +1 -1
- package/dist/commands/dev.js +308 -39
- package/dist/commands/dev.js.map +1 -1
- package/dist/commands/enable-builtin-pages.d.ts +3 -0
- package/dist/commands/enable-builtin-pages.d.ts.map +1 -0
- package/dist/commands/enable-builtin-pages.js +28 -0
- package/dist/commands/enable-builtin-pages.js.map +1 -0
- package/dist/commands/get-component-props.d.ts +3 -0
- package/dist/commands/get-component-props.d.ts.map +1 -0
- package/dist/commands/get-component-props.js +32 -0
- package/dist/commands/get-component-props.js.map +1 -0
- package/dist/commands/get-page-by-type.d.ts +3 -0
- package/dist/commands/get-page-by-type.d.ts.map +1 -0
- package/dist/commands/get-page-by-type.js +25 -0
- package/dist/commands/get-page-by-type.js.map +1 -0
- package/dist/commands/get-section-values.d.ts +3 -0
- package/dist/commands/get-section-values.d.ts.map +1 -0
- package/dist/commands/get-section-values.js +39 -0
- package/dist/commands/get-section-values.js.map +1 -0
- package/dist/commands/list-builtin-pages.d.ts +3 -0
- package/dist/commands/list-builtin-pages.d.ts.map +1 -0
- package/dist/commands/list-builtin-pages.js +28 -0
- package/dist/commands/list-builtin-pages.js.map +1 -0
- package/dist/commands/list-entities.d.ts +3 -0
- package/dist/commands/list-entities.d.ts.map +1 -0
- package/dist/commands/list-entities.js +32 -0
- package/dist/commands/list-entities.js.map +1 -0
- package/dist/commands/list-page-sections.d.ts.map +1 -1
- package/dist/commands/list-page-sections.js +8 -2
- package/dist/commands/list-page-sections.js.map +1 -1
- package/dist/commands/list-theme-globals.d.ts +3 -0
- package/dist/commands/list-theme-globals.d.ts.map +1 -0
- package/dist/commands/list-theme-globals.js +22 -0
- package/dist/commands/list-theme-globals.js.map +1 -0
- package/dist/commands/list-translations.d.ts +3 -0
- package/dist/commands/list-translations.d.ts.map +1 -0
- package/dist/commands/list-translations.js +33 -0
- package/dist/commands/list-translations.js.map +1 -0
- package/dist/commands/move-page-section.d.ts +3 -0
- package/dist/commands/move-page-section.d.ts.map +1 -0
- package/dist/commands/move-page-section.js +62 -0
- package/dist/commands/move-page-section.js.map +1 -0
- package/dist/commands/publish-theme.d.ts +3 -0
- package/dist/commands/publish-theme.d.ts.map +1 -0
- package/dist/commands/publish-theme.js +29 -0
- package/dist/commands/publish-theme.js.map +1 -0
- package/dist/commands/publish.d.ts.map +1 -1
- package/dist/commands/publish.js +65 -3
- package/dist/commands/publish.js.map +1 -1
- package/dist/commands/remove-page-section.d.ts +3 -0
- package/dist/commands/remove-page-section.d.ts.map +1 -0
- package/dist/commands/remove-page-section.js +40 -0
- package/dist/commands/remove-page-section.js.map +1 -0
- package/dist/commands/search-products.d.ts +3 -0
- package/dist/commands/search-products.d.ts.map +1 -0
- package/dist/commands/search-products.js +40 -0
- package/dist/commands/search-products.js.map +1 -0
- package/dist/commands/translation-languages.d.ts +3 -0
- package/dist/commands/translation-languages.d.ts.map +1 -0
- package/dist/commands/translation-languages.js +43 -0
- package/dist/commands/translation-languages.js.map +1 -0
- package/dist/commands/update-builtin-page-prop.d.ts +3 -0
- package/dist/commands/update-builtin-page-prop.d.ts.map +1 -0
- package/dist/commands/update-builtin-page-prop.js +49 -0
- package/dist/commands/update-builtin-page-prop.js.map +1 -0
- package/dist/commands/update-global-variable.d.ts +3 -0
- package/dist/commands/update-global-variable.d.ts.map +1 -0
- package/dist/commands/update-global-variable.js +70 -0
- package/dist/commands/update-global-variable.js.map +1 -0
- package/dist/commands/update-page-sections.d.ts +3 -0
- package/dist/commands/update-page-sections.d.ts.map +1 -0
- package/dist/commands/update-page-sections.js +39 -0
- package/dist/commands/update-page-sections.js.map +1 -0
- package/dist/commands/update-section-prop.d.ts.map +1 -1
- package/dist/commands/update-section-prop.js +25 -8
- package/dist/commands/update-section-prop.js.map +1 -1
- package/dist/commands/update-translations.d.ts +3 -0
- package/dist/commands/update-translations.d.ts.map +1 -0
- package/dist/commands/update-translations.js +37 -0
- package/dist/commands/update-translations.js.map +1 -0
- package/dist/commands/upload-image.d.ts.map +1 -1
- package/dist/commands/upload-image.js +5 -46
- package/dist/commands/upload-image.js.map +1 -1
- package/dist/commands/upload-images.d.ts +3 -0
- package/dist/commands/upload-images.d.ts.map +1 -0
- package/dist/commands/upload-images.js +48 -0
- package/dist/commands/upload-images.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +60 -1
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +77 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/archive-project.d.ts +50 -0
- package/dist/utils/archive-project.d.ts.map +1 -0
- package/dist/utils/archive-project.js +178 -0
- package/dist/utils/archive-project.js.map +1 -0
- package/dist/utils/compile.d.ts +17 -2
- package/dist/utils/compile.d.ts.map +1 -1
- package/dist/utils/compile.js +759 -117
- package/dist/utils/compile.js.map +1 -1
- package/dist/utils/component-helpers.d.ts +222 -4
- package/dist/utils/component-helpers.d.ts.map +1 -1
- package/dist/utils/component-helpers.js +558 -37
- package/dist/utils/component-helpers.js.map +1 -1
- package/dist/utils/css-import-resolver.d.ts +4 -1
- package/dist/utils/css-import-resolver.d.ts.map +1 -1
- package/dist/utils/css-import-resolver.js +9 -1
- package/dist/utils/css-import-resolver.js.map +1 -1
- package/dist/utils/dev-server-auth.d.ts +19 -0
- package/dist/utils/dev-server-auth.d.ts.map +1 -0
- package/dist/utils/dev-server-auth.js +60 -0
- package/dist/utils/dev-server-auth.js.map +1 -0
- package/dist/utils/editor-action-client.d.ts +4 -3
- package/dist/utils/editor-action-client.d.ts.map +1 -1
- package/dist/utils/editor-action-client.js +56 -19
- package/dist/utils/editor-action-client.js.map +1 -1
- package/dist/utils/esm-transform.d.ts +30 -0
- package/dist/utils/esm-transform.d.ts.map +1 -1
- package/dist/utils/esm-transform.js +169 -2
- package/dist/utils/esm-transform.js.map +1 -1
- package/dist/utils/find-component-for-file.d.ts +12 -0
- package/dist/utils/find-component-for-file.d.ts.map +1 -0
- package/dist/utils/find-component-for-file.js +24 -0
- package/dist/utils/find-component-for-file.js.map +1 -0
- package/dist/utils/forbid-deep-imports.d.ts +3 -0
- package/dist/utils/forbid-deep-imports.d.ts.map +1 -0
- package/dist/utils/forbid-deep-imports.js +54 -0
- package/dist/utils/forbid-deep-imports.js.map +1 -0
- package/dist/utils/forbid-external-packages.d.ts +26 -0
- package/dist/utils/forbid-external-packages.d.ts.map +1 -0
- package/dist/utils/forbid-external-packages.js +99 -0
- package/dist/utils/forbid-external-packages.js.map +1 -0
- package/dist/utils/i18n.d.ts +80 -0
- package/dist/utils/i18n.d.ts.map +1 -0
- package/dist/utils/i18n.js +265 -0
- package/dist/utils/i18n.js.map +1 -0
- package/dist/utils/load-image.d.ts +16 -0
- package/dist/utils/load-image.d.ts.map +1 -0
- package/dist/utils/load-image.js +50 -0
- package/dist/utils/load-image.js.map +1 -0
- package/dist/utils/storefront-t.d.ts +17 -0
- package/dist/utils/storefront-t.d.ts.map +1 -0
- package/dist/utils/storefront-t.js +186 -0
- package/dist/utils/storefront-t.js.map +1 -0
- package/dist/utils/vendor-storefront.d.ts +13 -0
- package/dist/utils/vendor-storefront.d.ts.map +1 -0
- package/dist/utils/vendor-storefront.js +91 -0
- package/dist/utils/vendor-storefront.js.map +1 -0
- package/dist/utils/websocket-server.d.ts +161 -7
- package/dist/utils/websocket-server.d.ts.map +1 -1
- package/dist/utils/websocket-server.js +324 -45
- package/dist/utils/websocket-server.js.map +1 -1
- package/package.json +19 -2
- package/templates/add/section.css +11 -0
- package/dist/commands/create.d.ts +0 -4
- package/dist/commands/create.d.ts.map +0 -1
- package/dist/commands/create.js +0 -228
- package/dist/commands/create.js.map +0 -1
- package/dist/commands/proxy.d.ts +0 -39
- package/dist/commands/proxy.d.ts.map +0 -1
- package/dist/commands/proxy.js +0 -210
- package/dist/commands/proxy.js.map +0 -1
|
@@ -67,9 +67,151 @@ function isChunkImport(moduleName) {
|
|
|
67
67
|
function chunkIdFromImport(moduleName) {
|
|
68
68
|
return moduleName.replace(/^\.\//, "").replace(/\.js$/, "");
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* A dynamic import with a literal specifier: `import("./chunk-ABCD.js")`.
|
|
72
|
+
*
|
|
73
|
+
* The `(` is what keeps every other rule in this file from seeing these: each static form expects
|
|
74
|
+
* `{`, `*`, an identifier or a quote right after `import`, so a dynamic one falls through all of
|
|
75
|
+
* them — the catch-all strippers at the bottom included.
|
|
76
|
+
*
|
|
77
|
+
* Falling through is not harmless. A native `import()` in canvas-evaluated code resolves against
|
|
78
|
+
* the URL of the module doing the evaluating, i.e. the EDITOR's own source tree, so the browser
|
|
79
|
+
* goes looking for `chunk-ABCD.js` next to that module and gets a 404. The chunk is already in
|
|
80
|
+
* `window.__cc_chunks` — it just has to be asked for by name instead of by URL. This mirrors
|
|
81
|
+
* DYNAMIC_IMPORT_RE in the production loader (apps/code-generator/.../_ikas-builtin/evaluate.ts),
|
|
82
|
+
* which fixes the same shape on the published side.
|
|
83
|
+
*
|
|
84
|
+
* The 404 is quiet in the worst way: components lazy-import on interaction paths (a mobile menu,
|
|
85
|
+
* a cart drawer), so it surfaces as a button that does nothing, far from the code that failed.
|
|
86
|
+
*/
|
|
87
|
+
const DYNAMIC_IMPORT_RE = /\bimport\s*\(\s*(["'])([^"']+)\1\s*\)/g;
|
|
88
|
+
/** Start of any dynamic import, literal or not. `import.meta` has a `.` and never matches. */
|
|
89
|
+
const DYNAMIC_IMPORT_OPENER_RE = /\bimport\s*\(/g;
|
|
90
|
+
/**
|
|
91
|
+
* DYNAMIC_IMPORT_RE, derived rather than hand-copied so the guard below asks the one question that
|
|
92
|
+
* matters — "would the rewrite above reach this?" — and can never drift into a different answer.
|
|
93
|
+
* Sticky, so it can be tested at an opener's position without slicing the rest of the file.
|
|
94
|
+
*
|
|
95
|
+
* Anything the rewrite cannot express is therefore reported, `import("./x.js", { with: … })`
|
|
96
|
+
* included. That is not a false positive: the rewrite would leave that call native too.
|
|
97
|
+
*/
|
|
98
|
+
const REWRITABLE_DYNAMIC_IMPORT_RE = new RegExp(DYNAMIC_IMPORT_RE.source, "y");
|
|
99
|
+
/** How much of an offending call to quote back, so the message locates it without dumping a bundle. */
|
|
100
|
+
const OFFENDER_EXCERPT_LENGTH = 60;
|
|
101
|
+
/** `import` still followed by a module reference — `(`, or the quote of a bare/from-less form. */
|
|
102
|
+
const RESIDUAL_IMPORT_RE = /\bimport\s*[({"']/g;
|
|
103
|
+
/** What the catch-all strippers leave behind. It quotes the original `import`, so exclude it. */
|
|
104
|
+
const STRIPPED_IMPORT_COMMENT_RE = /\/\* stripped:[\s\S]*?\*\//g;
|
|
105
|
+
/**
|
|
106
|
+
* Every rewrite in `transformEsmToWindowGlobals` matches ONE syntactic form, and this file's
|
|
107
|
+
* recurring failure is a form that matches none of them: the dynamic import went unhandled for
|
|
108
|
+
* exactly that reason, silently, until someone clicked a mobile menu. Enumerating the forms we know
|
|
109
|
+
* about cannot catch the next one — so check the OUTPUT instead. Canvas code is handed to `eval`,
|
|
110
|
+
* where any surviving module reference fails, so anything still shaped like one is a miss.
|
|
111
|
+
*/
|
|
112
|
+
function findResidualImports(code) {
|
|
113
|
+
const cleaned = code.replace(STRIPPED_IMPORT_COMMENT_RE, "");
|
|
114
|
+
const residual = [];
|
|
115
|
+
RESIDUAL_IMPORT_RE.lastIndex = 0;
|
|
116
|
+
for (const match of cleaned.matchAll(RESIDUAL_IMPORT_RE)) {
|
|
117
|
+
const start = match.index ?? 0;
|
|
118
|
+
residual.push(cleaned.slice(start, start + OFFENDER_EXCERPT_LENGTH));
|
|
119
|
+
}
|
|
120
|
+
return residual;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Find dynamic imports the rewrite above cannot reach — anything whose specifier is not a plain
|
|
124
|
+
* string literal: `import(spec)`, `import(`./chunk-${h}.js`)`, `import("./chunk-" + h + ".js")`.
|
|
125
|
+
*
|
|
126
|
+
* Such a call stays a native `import()` in canvas code and 404s against the editor's own URL, which
|
|
127
|
+
* is the exact failure DYNAMIC_IMPORT_RE exists to remove — only silent, and only on whichever lazy
|
|
128
|
+
* path first reaches it. The compiler emits literal specifiers for every chunk it splits, so this
|
|
129
|
+
* should never fire; it is here so the first one that does is reported at build time rather than
|
|
130
|
+
* in a partner's preview. Mirrors the guard in
|
|
131
|
+
* packages/builtin-components/scripts/build-bundle.ts, which throws — both callers here only warn
|
|
132
|
+
* for now, for the reason spelled out in commands/publish.ts.
|
|
133
|
+
*
|
|
134
|
+
* Returns a short excerpt per offender, in source order.
|
|
135
|
+
*/
|
|
136
|
+
export function findComputedDynamicImports(code) {
|
|
137
|
+
const offenders = [];
|
|
138
|
+
// Both constants carry a `lastIndex`. Write it before every read: a stale value would make this
|
|
139
|
+
// gate skip the head of a file and report nothing, and a publish gate that fails open is worse
|
|
140
|
+
// than no gate at all.
|
|
141
|
+
DYNAMIC_IMPORT_OPENER_RE.lastIndex = 0;
|
|
142
|
+
for (const match of code.matchAll(DYNAMIC_IMPORT_OPENER_RE)) {
|
|
143
|
+
const start = match.index ?? 0;
|
|
144
|
+
REWRITABLE_DYNAMIC_IMPORT_RE.lastIndex = start;
|
|
145
|
+
if (REWRITABLE_DYNAMIC_IMPORT_RE.test(code))
|
|
146
|
+
continue;
|
|
147
|
+
offenders.push(code.slice(start, start + OFFENDER_EXCERPT_LENGTH));
|
|
148
|
+
}
|
|
149
|
+
return offenders;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Run the guard over a whole compilation and label every offender with where it came from.
|
|
153
|
+
*
|
|
154
|
+
* Both commands scan the same two maps, and when they each did it themselves they drifted: `dev`
|
|
155
|
+
* looked only at the client build, so a computed specifier in server-only code drew no warning and
|
|
156
|
+
* then hard-failed at publish — the exact surprise the dev warning exists to prevent. One pass, so
|
|
157
|
+
* the two can only ever disagree about severity.
|
|
158
|
+
*/
|
|
159
|
+
export function findComputedDynamicImportsInBundles(chunks, entries, entryLabels) {
|
|
160
|
+
const offenders = [];
|
|
161
|
+
const scan = (label, bundle) => {
|
|
162
|
+
for (const offender of findComputedDynamicImports(bundle.clientJs)) {
|
|
163
|
+
offenders.push(`${label} (client): ${offender}`);
|
|
164
|
+
}
|
|
165
|
+
for (const offender of findComputedDynamicImports(bundle.serverJs)) {
|
|
166
|
+
offenders.push(`${label} (server): ${offender}`);
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
for (const [chunkId, chunk] of chunks)
|
|
170
|
+
scan(`chunk ${chunkId}`, chunk);
|
|
171
|
+
for (const [id, entry] of entries)
|
|
172
|
+
scan(entryLabels?.get(id) || id, entry);
|
|
173
|
+
return offenders;
|
|
174
|
+
}
|
|
70
175
|
export function transformEsmToWindowGlobals(code, options) {
|
|
71
176
|
let transformed = code;
|
|
72
177
|
const chunkMapping = options?.chunkMapping;
|
|
178
|
+
// Transform dynamic imports: import("./chunk-ABCD.js"), import("preact/hooks")
|
|
179
|
+
//
|
|
180
|
+
// Chunks and externals both matter here. A chunk import resolves against the URL of whatever
|
|
181
|
+
// evaluated the code — in the canvas, the editor's own source tree — and 404s. An external is
|
|
182
|
+
// worse: a bare specifier has no base URL to resolve against at all, so it throws outright.
|
|
183
|
+
//
|
|
184
|
+
// The target is read inside the `.then` callback rather than inline, which keeps the one property
|
|
185
|
+
// of a real dynamic import that matters here: it is resolved AFTER the importing module has
|
|
186
|
+
// finished. A chunk's registry slot is filled by its own IIFE, and a dynamic import is what the
|
|
187
|
+
// compiler emits to defer a chunk in the first place — resolving inline would demand an
|
|
188
|
+
// evaluation order the compiler never promised.
|
|
189
|
+
//
|
|
190
|
+
// A dynamic import yields a module namespace, so an external maps to the bare global, exactly as
|
|
191
|
+
// the `import * as ns` pass does — not the `.default || global` unwrap the default-import pass
|
|
192
|
+
// applies.
|
|
193
|
+
//
|
|
194
|
+
// The chunk id is written out in full because it is the same literal every other pass emits, and
|
|
195
|
+
// sortSharedModulesByDependency (apps/editor/src/codegen/design-generator) reads those literals
|
|
196
|
+
// as eval-order edges. Pruning does not depend on it — collectReferencedSharedModuleIds always
|
|
197
|
+
// reconciles against the raw `./chunk-*.js` in the compiled bundles — so this only has to avoid
|
|
198
|
+
// being wrong, and a lazy edge treated as eager is safe here: every chunk is evaluated up front
|
|
199
|
+
// on the canvas anyway.
|
|
200
|
+
transformed = transformed.replace(DYNAMIC_IMPORT_RE, (match, _quote, moduleName) => {
|
|
201
|
+
if (isChunkImport(moduleName)) {
|
|
202
|
+
if (!chunkMapping)
|
|
203
|
+
return match;
|
|
204
|
+
const chunkId = chunkIdFromImport(moduleName);
|
|
205
|
+
const registryKey = chunkMapping.get(chunkId) || chunkId;
|
|
206
|
+
return `Promise.resolve().then(()=>window.__cc_chunks["${registryKey}"])`;
|
|
207
|
+
}
|
|
208
|
+
const globalName = resolveModuleGlobal(moduleName);
|
|
209
|
+
if (globalName) {
|
|
210
|
+
return `Promise.resolve().then(()=>${globalName})`;
|
|
211
|
+
}
|
|
212
|
+
// Nothing to map it to. Left native, and reported by the post-condition at the end.
|
|
213
|
+
return match;
|
|
214
|
+
});
|
|
73
215
|
// Transform named imports: import { a, b } from "module";
|
|
74
216
|
transformed = transformed.replace(/import\s*\{([^}]+)\}\s*from\s*["']([^"']+)["']\s*;?/g, (match, imports, moduleName) => {
|
|
75
217
|
// Handle chunk imports
|
|
@@ -172,13 +314,38 @@ export function transformEsmToWindowGlobals(code, options) {
|
|
|
172
314
|
console.warn(`[esm-transform] Unhandled import stripped: ${match}`);
|
|
173
315
|
return `/* stripped: ${match} */`;
|
|
174
316
|
});
|
|
175
|
-
//
|
|
176
|
-
|
|
317
|
+
// Bare `import "module"` side-effect imports.
|
|
318
|
+
//
|
|
319
|
+
// A side-effect import of a CHUNK cannot simply be dropped. The canvas derives its evaluation
|
|
320
|
+
// order from the `window.__cc_chunks["<id>"]` literals it finds in each module's code
|
|
321
|
+
// (sortSharedModulesByDependency in apps/editor/src/codegen/design-generator), so a stripped
|
|
322
|
+
// import silently deletes a dependency EDGE: the chunk is still evaluated, but nothing keeps it
|
|
323
|
+
// ordered before the module relying on its module-level initialisation. Emitting a bare
|
|
324
|
+
// registry reference keeps the edge visible and does nothing at runtime.
|
|
325
|
+
//
|
|
326
|
+
// This stayed harmless while components imported the storefront SDK as an external. Vendoring
|
|
327
|
+
// it pulls the SDK's module-level initialisation (observable stores, static class fields) into
|
|
328
|
+
// the chunk graph, which is exactly the code whose ordering matters.
|
|
329
|
+
transformed = transformed.replace(/import\s*["']([^"']+)["']\s*;?/g, (match, moduleName) => {
|
|
330
|
+
if (chunkMapping && isChunkImport(moduleName)) {
|
|
331
|
+
const chunkId = chunkIdFromImport(moduleName);
|
|
332
|
+
const registryKey = chunkMapping.get(chunkId) || chunkId;
|
|
333
|
+
return `window.__cc_chunks["${registryKey}"];`;
|
|
334
|
+
}
|
|
177
335
|
console.warn(`[esm-transform] Side-effect import stripped: ${match}`);
|
|
178
336
|
return `/* stripped: ${match} */`;
|
|
179
337
|
});
|
|
180
338
|
// Strip any remaining `export` keywords as a final pass
|
|
181
339
|
transformed = transformed.replace(/\bexport\s+/g, "");
|
|
340
|
+
// Post-condition: nothing that still looks like a module reference may leave this function.
|
|
341
|
+
// A warning rather than a throw — a dynamic import of an unrecognised specifier is deliberately
|
|
342
|
+
// left native above (there is nothing to map it to), and neither `dev` nor `publish` should die
|
|
343
|
+
// on a shape this transform has merely never been taught.
|
|
344
|
+
const residual = findResidualImports(transformed);
|
|
345
|
+
if (residual.length > 0) {
|
|
346
|
+
console.warn(`[esm-transform] ${residual.length} import(s) survived the transform and will fail in the canvas: ` +
|
|
347
|
+
residual.join(" | "));
|
|
348
|
+
}
|
|
182
349
|
return transformed;
|
|
183
350
|
}
|
|
184
351
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esm-transform.js","sourceRoot":"","sources":["../../src/utils/esm-transform.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;GAEG;AACH,MAAM,gBAAgB,GAA2B;IAC/C,QAAQ,EAAE,eAAe;IAC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get the component definition that contains a file path.
|
|
4
|
+
*
|
|
5
|
+
* Accepts relative or absolute paths: chokidar emits paths relative to cwd for the dev
|
|
6
|
+
* server's relative watch patterns, so the incoming path is resolved here (normalize alone
|
|
7
|
+
* would leave it relative and it could never match the absolute entry/styles/dir paths below).
|
|
8
|
+
*/
|
|
9
|
+
export declare function findComponentForFile(config: {
|
|
10
|
+
components: ComponentDefinition[];
|
|
11
|
+
}, filePath: string): ComponentDefinition | null;
|
|
12
|
+
//# sourceMappingURL=find-component-for-file.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-component-for-file.d.ts","sourceRoot":"","sources":["../../src/utils/find-component-for-file.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAClC,MAAM,EAAE;IAAE,UAAU,EAAE,mBAAmB,EAAE,CAAA;CAAE,EAC7C,QAAQ,EAAE,MAAM,GACf,mBAAmB,GAAG,IAAI,CAmB5B"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import * as path from "path";
|
|
2
|
+
/**
|
|
3
|
+
* Get the component definition that contains a file path.
|
|
4
|
+
*
|
|
5
|
+
* Accepts relative or absolute paths: chokidar emits paths relative to cwd for the dev
|
|
6
|
+
* server's relative watch patterns, so the incoming path is resolved here (normalize alone
|
|
7
|
+
* would leave it relative and it could never match the absolute entry/styles/dir paths below).
|
|
8
|
+
*/
|
|
9
|
+
export function findComponentForFile(config, filePath) {
|
|
10
|
+
const normalizedPath = path.resolve(filePath);
|
|
11
|
+
for (const component of config.components) {
|
|
12
|
+
const entryPath = path.resolve(process.cwd(), component.entry);
|
|
13
|
+
const stylesPath = path.resolve(process.cwd(), component.styles);
|
|
14
|
+
const componentDir = path.dirname(entryPath);
|
|
15
|
+
// Check if the file is the entry, styles, or in the component directory
|
|
16
|
+
if (normalizedPath === entryPath ||
|
|
17
|
+
normalizedPath === stylesPath ||
|
|
18
|
+
normalizedPath.startsWith(componentDir + path.sep)) {
|
|
19
|
+
return component;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=find-component-for-file.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"find-component-for-file.js","sourceRoot":"","sources":["../../src/utils/find-component-for-file.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAG7B;;;;;;GAMG;AACH,MAAM,UAAU,oBAAoB,CAClC,MAA6C,EAC7C,QAAgB;IAEhB,MAAM,cAAc,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;IAE9C,KAAK,MAAM,SAAS,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;QAC1C,MAAM,SAAS,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC,KAAK,CAAC,CAAC;QAC/D,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC;QACjE,MAAM,YAAY,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAE7C,wEAAwE;QACxE,IACE,cAAc,KAAK,SAAS;YAC5B,cAAc,KAAK,UAAU;YAC7B,cAAc,CAAC,UAAU,CAAC,YAAY,GAAG,IAAI,CAAC,GAAG,CAAC,EAClD,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forbid-deep-imports.d.ts","sourceRoot":"","sources":["../../src/utils/forbid-deep-imports.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AA2BtC,wBAAgB,iCAAiC,IAAI,MAAM,CA6B1D"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fail the build on deep imports into the storefront packages.
|
|
3
|
+
*
|
|
4
|
+
* `@ikas/bp-storefront` (and its `-models` / `-config` / `-api` siblings) are marked
|
|
5
|
+
* EXTERNAL during compilation, so esbuild does NOT resolve their subpaths — a hand-written
|
|
6
|
+
* deep import like `@ikas/bp-storefront/dist/functions/api/cart` would otherwise sail through
|
|
7
|
+
* the bundle untouched and only break later (the published storefront exposes the package as
|
|
8
|
+
* window globals keyed off the ROOT export names; a `/dist/...` or `/src/...` subpath has no
|
|
9
|
+
* corresponding global, so the component throws at runtime in the canvas/published theme).
|
|
10
|
+
*
|
|
11
|
+
* The public contract is: import ONLY from the bare package root. Anything after the package
|
|
12
|
+
* name is a private path. This plugin turns that contract into a hard compile error with a
|
|
13
|
+
* message pointing at the correct root import, instead of letting the component build "succeed"
|
|
14
|
+
* and fail in the browser. Models often reach for these subpaths when they can't find a public
|
|
15
|
+
* helper (e.g. coupon code) — the error nudges them back to the documented root exports.
|
|
16
|
+
*/
|
|
17
|
+
// Matches `@ikas/bp-storefront` (and its -models / -config / -api siblings) with an OPTIONAL
|
|
18
|
+
// subpath. Group 1 = package root, group 2 = the subpath (including its leading "/"), if any.
|
|
19
|
+
//
|
|
20
|
+
// NOTE: these packages MUST NOT also sit in esbuild's `external: [...]` array. esbuild applies
|
|
21
|
+
// the external array BEFORE running plugin onResolve callbacks, so an external-listed deep
|
|
22
|
+
// import is short-circuited and the plugin never sees it. We therefore externalize the valid
|
|
23
|
+
// ROOT import from inside this plugin instead, which lets the same callback reject subpaths.
|
|
24
|
+
const STOREFRONT_PKG = /^(@ikas\/bp-storefront(?:-(?:models|config|api))?)(\/.*)?$/;
|
|
25
|
+
export function forbidDeepStorefrontImportsPlugin() {
|
|
26
|
+
return {
|
|
27
|
+
name: "ikas-forbid-deep-storefront-imports",
|
|
28
|
+
setup(build) {
|
|
29
|
+
build.onResolve({ filter: STOREFRONT_PKG }, (args) => {
|
|
30
|
+
const [, root, subpath] = args.path.match(STOREFRONT_PKG);
|
|
31
|
+
// Bare root import (or a lone trailing slash) — the allowed form. Externalize it, the
|
|
32
|
+
// same way the old `external: [...]` entry did, so the published storefront's window
|
|
33
|
+
// globals satisfy it.
|
|
34
|
+
if (!subpath || subpath === "/") {
|
|
35
|
+
return { path: root, external: true };
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
errors: [
|
|
39
|
+
{
|
|
40
|
+
text: `Deep import "${args.path}" is not allowed. Import only from the package root ` +
|
|
41
|
+
`"${root}" — e.g. import { saveCouponCode, getCart } from "${root}". ` +
|
|
42
|
+
`Subpaths like "/dist/..." or "/src/..." are private: they bundle fine but have ` +
|
|
43
|
+
`no window global in the published storefront, so the component breaks at runtime. ` +
|
|
44
|
+
`If a helper seems missing from the root, it almost always has a public name there ` +
|
|
45
|
+
`(coupon code, for instance, is getCouponCodeForm / setCouponCodeFormCouponCode / ` +
|
|
46
|
+
`submitCouponCodeForm).`,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=forbid-deep-imports.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forbid-deep-imports.js","sourceRoot":"","sources":["../../src/utils/forbid-deep-imports.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;GAeG;AACH,6FAA6F;AAC7F,8FAA8F;AAC9F,EAAE;AACF,+FAA+F;AAC/F,2FAA2F;AAC3F,6FAA6F;AAC7F,6FAA6F;AAC7F,MAAM,cAAc,GAAG,4DAA4D,CAAC;AAEpF,MAAM,UAAU,iCAAiC;IAC/C,OAAO;QACL,IAAI,EAAE,qCAAqC;QAC3C,KAAK,CAAC,KAAK;YACT,KAAK,CAAC,SAAS,CAAC,EAAE,MAAM,EAAE,cAAc,EAAE,EAAE,CAAC,IAAI,EAAE,EAAE;gBACnD,MAAM,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,cAAc,CAAE,CAAC;gBAC3D,sFAAsF;gBACtF,qFAAqF;gBACrF,sBAAsB;gBACtB,IAAI,CAAC,OAAO,IAAI,OAAO,KAAK,GAAG,EAAE,CAAC;oBAChC,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC;gBACxC,CAAC;gBACD,OAAO;oBACL,MAAM,EAAE;wBACN;4BACE,IAAI,EACF,gBAAgB,IAAI,CAAC,IAAI,sDAAsD;gCAC/E,IAAI,IAAI,qDAAqD,IAAI,KAAK;gCACtE,iFAAiF;gCACjF,oFAAoF;gCACpF,oFAAoF;gCACpF,mFAAmF;gCACnF,wBAAwB;yBAC3B;qBACF;iBACF,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Plugin } from "esbuild";
|
|
2
|
+
/**
|
|
3
|
+
* Fail the build when a code component imports an npm package that is not on the allowlist.
|
|
4
|
+
*
|
|
5
|
+
* Themes are untrusted source. Only the reference-theme baseline packages plus `three` and
|
|
6
|
+
* `animejs` may be bundled into a component. Anything else (lodash, axios, a random UI kit, ...)
|
|
7
|
+
* becomes a hard compile error instead of a silently-bundled dependency — so installing an extra
|
|
8
|
+
* package and importing it blows the build up immediately with an actionable message.
|
|
9
|
+
*
|
|
10
|
+
* NOTE: esbuild applies the `external: [...]` array BEFORE plugin onResolve, so the externalized
|
|
11
|
+
* runtime packages (preact, preact/hooks, mobx, preact-render-to-string) are short-circuited and
|
|
12
|
+
* never reach this plugin — they are allowed implicitly. Non-external subpaths (e.g.
|
|
13
|
+
* `preact/compat`) DO reach here and resolve to an allowed root.
|
|
14
|
+
*/
|
|
15
|
+
export declare function forbidExternalPackagesPlugin(options?: {
|
|
16
|
+
/**
|
|
17
|
+
* Importers whose bare imports bypass the allowlist entirely.
|
|
18
|
+
*
|
|
19
|
+
* Set only when a package is vendored into the artifact (see `vendorStorefrontPlugin`). The
|
|
20
|
+
* allowlist governs what a component *author* may reach for; once we choose to bundle the
|
|
21
|
+
* storefront SDK, its own dependencies (`lodash`, `uuid`, ...) come along as a consequence of
|
|
22
|
+
* that choice, and rejecting them would just be the build arguing with itself.
|
|
23
|
+
*/
|
|
24
|
+
allowFrom?: (importer: string) => boolean;
|
|
25
|
+
}): Plugin;
|
|
26
|
+
//# sourceMappingURL=forbid-external-packages.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forbid-external-packages.d.ts","sourceRoot":"","sources":["../../src/utils/forbid-external-packages.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAqDtC;;;;;;;;;;;;GAYG;AACH,wBAAgB,4BAA4B,CAAC,OAAO,CAAC,EAAE;IACrD;;;;;;;OAOG;IACH,SAAS,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,KAAK,OAAO,CAAC;CAC3C,GAAG,MAAM,CAoCT"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import path from "path";
|
|
2
|
+
import { builtinModules } from "module";
|
|
3
|
+
/**
|
|
4
|
+
* Allowlist of npm packages a theme's code components are permitted to import.
|
|
5
|
+
*
|
|
6
|
+
* Intentionally STATIC — it is NOT derived from the theme's own package.json. The whole point
|
|
7
|
+
* is to stop themes from pulling in arbitrary third-party packages, so trusting their manifest
|
|
8
|
+
* would defeat the purpose: a theme could just add the dependency there. Instead we pin the set
|
|
9
|
+
* here, mirroring apps/reference-theme/package.json's runtime dependencies plus the two
|
|
10
|
+
* explicitly-permitted libraries.
|
|
11
|
+
*
|
|
12
|
+
* The list holds package ROOTS. Subpaths resolve to their root (e.g. `preact/hooks` → `preact`,
|
|
13
|
+
* `three/examples/jsm/...` → `three`), so every subpath of an allowed package is allowed too.
|
|
14
|
+
* Deep imports into the storefront SDK are separately restricted by
|
|
15
|
+
* `forbidDeepStorefrontImportsPlugin` (which runs first).
|
|
16
|
+
*/
|
|
17
|
+
const ALLOWED_PACKAGE_ROOTS = new Set([
|
|
18
|
+
// Preact runtime (root + any subpath: preact/hooks, preact/compat, preact/jsx-runtime, ...).
|
|
19
|
+
// The bare `preact` / `preact/hooks` specifiers are externalized (short-circuited before this
|
|
20
|
+
// plugin runs), but non-external subpaths like `preact/compat` still resolve through here.
|
|
21
|
+
"preact",
|
|
22
|
+
// MobX reactivity — pulled in by the injected observer runtime. Externalized in both builds,
|
|
23
|
+
// so this is a guard in case the externals list ever changes rather than a reachable import.
|
|
24
|
+
"mobx",
|
|
25
|
+
// ikas storefront SDK (deep-import rules enforced by forbidDeepStorefrontImportsPlugin)
|
|
26
|
+
"@ikas/bp-storefront",
|
|
27
|
+
"@ikas/bp-storefront-models",
|
|
28
|
+
"@ikas/bp-storefront-config",
|
|
29
|
+
"@ikas/bp-storefront-api",
|
|
30
|
+
// Virtual module injected by ikasComponentUtilsPlugin
|
|
31
|
+
"@ikas/component-utils",
|
|
32
|
+
// Explicitly permitted third-party libraries for themes
|
|
33
|
+
"three",
|
|
34
|
+
"animejs",
|
|
35
|
+
]);
|
|
36
|
+
// Node built-ins (with and without the `node:` prefix). Only an already-allowed package would
|
|
37
|
+
// reach for these, and platform:node externalizes them anyway — never flag them.
|
|
38
|
+
const NODE_BUILTINS = new Set([
|
|
39
|
+
...builtinModules,
|
|
40
|
+
...builtinModules.map((m) => `node:${m}`),
|
|
41
|
+
]);
|
|
42
|
+
/** Extract the package root from a bare import specifier (handles `@scope/name`). */
|
|
43
|
+
function packageRootOf(specifier) {
|
|
44
|
+
if (specifier.startsWith("@")) {
|
|
45
|
+
const parts = specifier.split("/");
|
|
46
|
+
return parts.slice(0, 2).join("/");
|
|
47
|
+
}
|
|
48
|
+
return specifier.split("/")[0];
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Fail the build when a code component imports an npm package that is not on the allowlist.
|
|
52
|
+
*
|
|
53
|
+
* Themes are untrusted source. Only the reference-theme baseline packages plus `three` and
|
|
54
|
+
* `animejs` may be bundled into a component. Anything else (lodash, axios, a random UI kit, ...)
|
|
55
|
+
* becomes a hard compile error instead of a silently-bundled dependency — so installing an extra
|
|
56
|
+
* package and importing it blows the build up immediately with an actionable message.
|
|
57
|
+
*
|
|
58
|
+
* NOTE: esbuild applies the `external: [...]` array BEFORE plugin onResolve, so the externalized
|
|
59
|
+
* runtime packages (preact, preact/hooks, mobx, preact-render-to-string) are short-circuited and
|
|
60
|
+
* never reach this plugin — they are allowed implicitly. Non-external subpaths (e.g.
|
|
61
|
+
* `preact/compat`) DO reach here and resolve to an allowed root.
|
|
62
|
+
*/
|
|
63
|
+
export function forbidExternalPackagesPlugin(options) {
|
|
64
|
+
return {
|
|
65
|
+
name: "ikas-forbid-external-packages",
|
|
66
|
+
setup(build) {
|
|
67
|
+
// Bare specifiers only — skip relative ("./", "../") and absolute ("/") imports.
|
|
68
|
+
build.onResolve({ filter: /^[^./]/ }, (args) => {
|
|
69
|
+
const specifier = args.path;
|
|
70
|
+
// Windows absolute paths (C:\..., C:/..., \\server\...) start with neither "." nor "/",
|
|
71
|
+
// so they slip past the bare-specifier filter above (esbuild's Go regex has no lookahead
|
|
72
|
+
// to exclude drive letters). Entry points and the injected JSX shim arrive here as
|
|
73
|
+
// absolute paths on Windows. win32.isAbsolute also accepts POSIX "/" paths, so this one
|
|
74
|
+
// check is safe on every platform — and bare npm specifiers can never contain ":".
|
|
75
|
+
if (path.win32.isAbsolute(specifier))
|
|
76
|
+
return undefined;
|
|
77
|
+
if (NODE_BUILTINS.has(specifier))
|
|
78
|
+
return undefined;
|
|
79
|
+
if (options?.allowFrom?.(args.importer))
|
|
80
|
+
return undefined;
|
|
81
|
+
const root = packageRootOf(specifier);
|
|
82
|
+
if (ALLOWED_PACKAGE_ROOTS.has(root))
|
|
83
|
+
return undefined;
|
|
84
|
+
return {
|
|
85
|
+
errors: [
|
|
86
|
+
{
|
|
87
|
+
text: `Package "${root}" is not allowed in ikas themes. ` +
|
|
88
|
+
`Code components may only import the default theme packages plus "three" and "animejs", ` +
|
|
89
|
+
`so installing and importing "${specifier}" fails the build by design. ` +
|
|
90
|
+
`Remove the dependency (inline the code you need, or switch to an allowed package). ` +
|
|
91
|
+
`Allowed packages: ${Array.from(ALLOWED_PACKAGE_ROOTS).sort().join(", ")}.`,
|
|
92
|
+
},
|
|
93
|
+
],
|
|
94
|
+
};
|
|
95
|
+
});
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=forbid-external-packages.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"forbid-external-packages.js","sourceRoot":"","sources":["../../src/utils/forbid-external-packages.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,cAAc,EAAE,MAAM,QAAQ,CAAC;AAExC;;;;;;;;;;;;;GAaG;AACH,MAAM,qBAAqB,GAAG,IAAI,GAAG,CAAS;IAC5C,6FAA6F;IAC7F,8FAA8F;IAC9F,2FAA2F;IAC3F,QAAQ;IACR,6FAA6F;IAC7F,6FAA6F;IAC7F,MAAM;IACN,wFAAwF;IACxF,qBAAqB;IACrB,4BAA4B;IAC5B,4BAA4B;IAC5B,yBAAyB;IACzB,sDAAsD;IACtD,uBAAuB;IACvB,wDAAwD;IACxD,OAAO;IACP,SAAS;CACV,CAAC,CAAC;AAEH,8FAA8F;AAC9F,iFAAiF;AACjF,MAAM,aAAa,GAAG,IAAI,GAAG,CAAS;IACpC,GAAG,cAAc;IACjB,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC;CAC1C,CAAC,CAAC;AAEH,qFAAqF;AACr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CACrF,qBAAqB,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,IAAI,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;yBAC9E;qBACF;iBACF,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import type { IkasComponentConfig } from "../types.js";
|
|
2
|
+
/**
|
|
3
|
+
* The project's UI texts: `<dir>/default.json` holds the base texts (every language's fallback), `<dir>/<locale>.json`
|
|
4
|
+
* a language's. Both are nested by group (`{ "common": { "addToCart": "Sepete ekle" } }`); a component reads them
|
|
5
|
+
* with `t("common.addToCart")` imported from `@ikas/bp-storefront` (the build binds it to them).
|
|
6
|
+
*/
|
|
7
|
+
export type I18nTree = {
|
|
8
|
+
[key: string]: string | I18nTree;
|
|
9
|
+
};
|
|
10
|
+
/** What the editor gets: the base texts and each language's, checked (see `readI18n`). */
|
|
11
|
+
export interface IProjectI18nData {
|
|
12
|
+
projectId: string;
|
|
13
|
+
base: I18nTree;
|
|
14
|
+
locales: Record<string, I18nTree>;
|
|
15
|
+
}
|
|
16
|
+
export declare const I18N_DEFAULT_FILE = "default";
|
|
17
|
+
/** A key's segment: an identifier, so a dotted path stays plain. */
|
|
18
|
+
export declare const I18N_SEGMENT_PATTERN: RegExp;
|
|
19
|
+
/** Whether `code` names a real language (`en`, `pt-BR`; not `xx` or `en-XX`). */
|
|
20
|
+
export declare function isLanguageCode(code: string): boolean;
|
|
21
|
+
/** The project's i18n folder, when its config names one. */
|
|
22
|
+
export declare function i18nDir(config: IkasComponentConfig, root?: string): string | null;
|
|
23
|
+
/** The `{{param}}` names a text uses. */
|
|
24
|
+
export declare function textParams(text: string): string[];
|
|
25
|
+
/** A tree's texts by dotted path; what is no text or group is reported, not kept. */
|
|
26
|
+
export declare function flattenI18n(tree: I18nTree, errors?: string[], prefix?: string): Record<string, string>;
|
|
27
|
+
/** Texts by dotted path back into a tree, keys sorted so a written file is stable. */
|
|
28
|
+
export declare function unflattenI18n(texts: Record<string, string>): I18nTree;
|
|
29
|
+
/**
|
|
30
|
+
* What is wrong with a language's texts against the base: a key the base lacks, or one whose `{{param}}`s differ
|
|
31
|
+
* from the base text's (`t()` passes the base's). Returns the valid texts too.
|
|
32
|
+
*/
|
|
33
|
+
export declare function checkLocaleTexts(base: Record<string, string>, texts: Record<string, string>, locale: string): {
|
|
34
|
+
valid: Record<string, string>;
|
|
35
|
+
errors: string[];
|
|
36
|
+
};
|
|
37
|
+
/**
|
|
38
|
+
* Reads the i18n folder. A file that is no valid JSON is reported and left out (`unreadable`: the caller keeps what
|
|
39
|
+
* it had); texts that break the rules are reported and left out, so the editor and the store get only valid ones.
|
|
40
|
+
*/
|
|
41
|
+
export declare function readI18n(dir: string): {
|
|
42
|
+
base: Record<string, string>;
|
|
43
|
+
locales: Record<string, Record<string, string>>;
|
|
44
|
+
errors: string[];
|
|
45
|
+
unreadable: string[];
|
|
46
|
+
};
|
|
47
|
+
/** The types file written next to the texts: what `import { t } from "@ikas/bp-storefront"` takes. */
|
|
48
|
+
export declare const I18N_TYPES_FILE = "index.d.ts";
|
|
49
|
+
/**
|
|
50
|
+
* The generated `<dir>/index.d.ts`: types only. It fills `UiTexts` of `@ikas/bp-storefront` with the base texts, so
|
|
51
|
+
* its `t` takes only the project's keys and their `{{param}}`s; the build binds that `t` to the project's texts.
|
|
52
|
+
*/
|
|
53
|
+
export declare function generateI18nTypes(base: Record<string, string>): string;
|
|
54
|
+
/**
|
|
55
|
+
* The `t` the build gives for `import { t } from "@ikas/bp-storefront"` (never written to the project): the store
|
|
56
|
+
* language's text of the project's `key`, else its base text, else the key; its `{{param}}`s filled in one pass.
|
|
57
|
+
*/
|
|
58
|
+
export declare function generateI18nRuntime(projectId: string, base: Record<string, string>): string;
|
|
59
|
+
/** Writes a file when its content changed: an unchanged write would wake the watcher for nothing. */
|
|
60
|
+
export declare function writeIfChanged(filePath: string, content: string): boolean;
|
|
61
|
+
/** Writes a language's texts (`default` for the base), sorted; no texts left removes a language's file. */
|
|
62
|
+
export declare function writeI18nFile(dir: string, locale: string, texts: Record<string, string>): boolean;
|
|
63
|
+
/**
|
|
64
|
+
* Reads the project's texts for the editor and writes the generated `index.d.ts`; `null` when the config names no
|
|
65
|
+
* folder. Problems are returned to be shown; a file that cannot be read keeps `previous`'s texts.
|
|
66
|
+
*/
|
|
67
|
+
export declare function loadProjectI18n(config: IkasComponentConfig, previous?: IProjectI18nData, root?: string): {
|
|
68
|
+
data: IProjectI18nData | undefined;
|
|
69
|
+
errors: string[];
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Writes the texts the editor saved (the base ones and the sent languages', nested) to the i18n folder: only a file
|
|
73
|
+
* whose texts changed is rewritten, a language with no texts left loses its file. Refused whole when one breaks the
|
|
74
|
+
* rules, so the files never hold what the editor would not show.
|
|
75
|
+
*/
|
|
76
|
+
export declare function writeEditorI18n(config: IkasComponentConfig, texts: {
|
|
77
|
+
base: I18nTree;
|
|
78
|
+
locales: Record<string, I18nTree>;
|
|
79
|
+
}, root?: string): string[];
|
|
80
|
+
//# sourceMappingURL=i18n.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"i18n.d.ts","sourceRoot":"","sources":["../../src/utils/i18n.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAEvD;;;;GAIG;AACH,MAAM,MAAM,QAAQ,GAAG;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,QAAQ,CAAA;CAAE,CAAC;AAE5D,0FAA0F;AAC1F,MAAM,WAAW,gBAAgB;IAC/B,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,QAAQ,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CACnC;AAED,eAAO,MAAM,iBAAiB,YAAY,CAAC;AAC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