@ohos-ports/zudoku 0.93.0-beta.1 → 0.93.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli/cli.js +55 -15
- package/package.json +1 -1
- package/src/vite/config.ts +8 -4
- package/src/vite/plugin-api-keys.ts +2 -1
- package/src/vite/plugin-api.ts +3 -2
- package/src/vite/plugin-auth.ts +2 -1
- package/src/vite/plugin-custom-pages.ts +2 -1
- package/src/vite/plugin-docs.ts +2 -1
- package/src/vite/plugin-navigation.ts +2 -1
- package/src/vite/plugin-search.ts +3 -2
- package/src/vite/plugin.ts +7 -1
- package/src/vite/self-reference.ts +58 -0
package/dist/cli/cli.js
CHANGED
|
@@ -326,6 +326,46 @@ var getPackageJsonPath = (pkg) => fileURLToPath(import.meta.resolve(`${pkg}/pack
|
|
|
326
326
|
var getPackageJson = (pkgPath) => JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
327
327
|
var getZudokuPackageJson = () => getPackageJson(getPackageJsonPath("@ohos-ports/zudoku"));
|
|
328
328
|
var getZudokuRootDir = () => path.dirname(getPackageJsonPath("@ohos-ports/zudoku"));
|
|
329
|
+
// Pre-publish fix (@ohos-ports/zudoku): pick the bare specifier under which THIS package
|
|
330
|
+
// instance is visible to the consumer's vite resolver (node_modules lookup), so generated
|
|
331
|
+
// code works under both canonical (@ohos-ports/zudoku) and npm-alias ("zudoku") installs.
|
|
332
|
+
var zudokuImportPrefix = (() => {
|
|
333
|
+
const root = getZudokuRootDir() + path.posix.sep;
|
|
334
|
+
for (const name of ["zudoku", "@ohos-ports/zudoku"]) {
|
|
335
|
+
try {
|
|
336
|
+
if (fileURLToPath(import.meta.resolve(name + "/package.json")).startsWith(root)) {
|
|
337
|
+
return name;
|
|
338
|
+
}
|
|
339
|
+
} catch {}
|
|
340
|
+
}
|
|
341
|
+
return "@ohos-ports/zudoku";
|
|
342
|
+
})();
|
|
343
|
+
// Pre-publish fix (@ohos-ports/zudoku): vite's resolver has no Node-style package
|
|
344
|
+
// self-reference; route bare "zudoku"/"@ohos-ports/zudoku" specifiers through
|
|
345
|
+
// import.meta.resolve (which honors package.json "name" self-reference) and accept
|
|
346
|
+
// the result only if it points into this package instance.
|
|
347
|
+
function zudokuSelfReferencePlugin() {
|
|
348
|
+
const root = getZudokuRootDir() + path.posix.sep;
|
|
349
|
+
return {
|
|
350
|
+
name: "zudoku:self-reference",
|
|
351
|
+
enforce: "pre",
|
|
352
|
+
resolveId(id) {
|
|
353
|
+
const queryMatch = id.match(/[?#].*$/);
|
|
354
|
+
const query = queryMatch ? queryMatch[0] : "";
|
|
355
|
+
const bare = query ? id.slice(0, id.length - query.length) : id;
|
|
356
|
+
if (!/^(?:@ohos-ports\/)?zudoku(\/.*)?$/.test(bare)) {
|
|
357
|
+
return null;
|
|
358
|
+
}
|
|
359
|
+
try {
|
|
360
|
+
const resolved = fileURLToPath(import.meta.resolve(bare));
|
|
361
|
+
if (resolved.startsWith(root)) {
|
|
362
|
+
return resolved + query;
|
|
363
|
+
}
|
|
364
|
+
} catch {}
|
|
365
|
+
return null;
|
|
366
|
+
},
|
|
367
|
+
};
|
|
368
|
+
}
|
|
329
369
|
|
|
330
370
|
// src/config/loader.ts
|
|
331
371
|
import { stat as stat2 } from "node:fs/promises";
|
|
@@ -4437,7 +4477,7 @@ var viteApiKeysPlugin = () => {
|
|
|
4437
4477
|
const deploymentName = ZuploEnv.buildConfig?.deploymentName || getZuploSystemConfigurations(process.env.ZUPLO_SYSTEM_CONFIGURATIONS)?.__ZUPLO_DEPLOYMENT_NAME;
|
|
4438
4478
|
const code = [
|
|
4439
4479
|
`import config from "virtual:zudoku-config";`,
|
|
4440
|
-
`import { apiKeyPlugin } from "
|
|
4480
|
+
`import { apiKeyPlugin } from "${zudokuImportPrefix}/plugins/api-keys";`,
|
|
4441
4481
|
`export const configuredApiKeysPlugin = apiKeyPlugin({
|
|
4442
4482
|
...config.apiKeys,
|
|
4443
4483
|
isZuplo: ${ZuploEnv.isZuplo},
|
|
@@ -6762,7 +6802,7 @@ export const rules = ${rulesCode};`,
|
|
|
6762
6802
|
if (hasMissingIcon) {
|
|
6763
6803
|
collectedIcons.add("MissingIcon");
|
|
6764
6804
|
}
|
|
6765
|
-
const importStatement = collectedIcons.size > 0 ? `import { ${[...collectedIcons].join(", ")} } from "
|
|
6805
|
+
const importStatement = collectedIcons.size > 0 ? `import { ${[...collectedIcons].join(", ")} } from "${zudokuImportPrefix}/icons";
|
|
6766
6806
|
` : "";
|
|
6767
6807
|
return [
|
|
6768
6808
|
importStatement,
|
|
@@ -6948,7 +6988,7 @@ var viteApiPlugin = async () => {
|
|
|
6948
6988
|
`const configuredApiCatalogPlugins = [];`
|
|
6949
6989
|
];
|
|
6950
6990
|
if (config.apis) {
|
|
6951
|
-
code.push(
|
|
6991
|
+
code.push(`import { openApiPlugin } from "${zudokuImportPrefix}/plugins/openapi";`);
|
|
6952
6992
|
code.push(
|
|
6953
6993
|
`const apis = Array.isArray(config.apis) ? config.apis : [config.apis]`
|
|
6954
6994
|
);
|
|
@@ -7050,7 +7090,7 @@ var viteApiPlugin = async () => {
|
|
|
7050
7090
|
}
|
|
7051
7091
|
if (config.catalogs) {
|
|
7052
7092
|
code.push(
|
|
7053
|
-
|
|
7093
|
+
`import { apiCatalogPlugin } from "${zudokuImportPrefix}/plugins/api-catalog";`
|
|
7054
7094
|
);
|
|
7055
7095
|
const catalogs = ensureArray(config.catalogs);
|
|
7056
7096
|
const categories = apis.flatMap((api) => api.categories ?? []).reduce((acc, catalog) => {
|
|
@@ -7139,7 +7179,7 @@ var viteAuthPlugin = () => {
|
|
|
7139
7179
|
...${JSON.stringify(config.authentication, null, 2)},
|
|
7140
7180
|
basePath: ${config.basePath ? JSON.stringify(config.basePath) : "undefined"},
|
|
7141
7181
|
};`,
|
|
7142
|
-
`import authProvider from "
|
|
7182
|
+
`import authProvider from "${zudokuImportPrefix}/auth/${config.authentication.type}";`,
|
|
7143
7183
|
`export const configuredAuthProvider = authProvider(config);`
|
|
7144
7184
|
].join("\n");
|
|
7145
7185
|
}
|
|
@@ -7171,7 +7211,7 @@ var viteConfigPlugin = () => {
|
|
|
7171
7211
|
}
|
|
7172
7212
|
return `
|
|
7173
7213
|
import rawConfig from "${normalizePath(configPath)}";
|
|
7174
|
-
import { runPluginTransformConfig } from "
|
|
7214
|
+
import { runPluginTransformConfig } from "${zudokuImportPrefix}/plugins";
|
|
7175
7215
|
|
|
7176
7216
|
const config = await runPluginTransformConfig(rawConfig);
|
|
7177
7217
|
export default config;
|
|
@@ -7226,7 +7266,7 @@ var viteCustomPagesPlugin = () => {
|
|
|
7226
7266
|
}
|
|
7227
7267
|
const code = [
|
|
7228
7268
|
`import config from "virtual:zudoku-config";`,
|
|
7229
|
-
`import { customPagesPlugin } from "
|
|
7269
|
+
`import { customPagesPlugin } from "${zudokuImportPrefix}/plugins/custom-pages";`,
|
|
7230
7270
|
`export const configuredCustomPagesPlugin = customPagesPlugin(config.navigation);`
|
|
7231
7271
|
];
|
|
7232
7272
|
return code.join("\n");
|
|
@@ -7406,7 +7446,7 @@ var viteDocsPlugin = () => {
|
|
|
7406
7446
|
return `export const configuredDocsPlugin = undefined;`;
|
|
7407
7447
|
}
|
|
7408
7448
|
const code = [
|
|
7409
|
-
|
|
7449
|
+
`import { markdownPlugin } from "${zudokuImportPrefix}/plugins/markdown";`
|
|
7410
7450
|
];
|
|
7411
7451
|
const fileMapping = await resolveCustomNavigationPaths(
|
|
7412
7452
|
config,
|
|
@@ -8464,7 +8504,7 @@ var viteSearchPlugin = () => {
|
|
|
8464
8504
|
if (config.search.type === "inkeep") {
|
|
8465
8505
|
code.push(
|
|
8466
8506
|
`import config from 'virtual:zudoku-config';`,
|
|
8467
|
-
`import { inkeepSearchPlugin } from "
|
|
8507
|
+
`import { inkeepSearchPlugin } from "${zudokuImportPrefix}/plugins/search-inkeep";`,
|
|
8468
8508
|
`export const configuredSearchPlugin = inkeepSearchPlugin(config.search);`
|
|
8469
8509
|
);
|
|
8470
8510
|
return code.join("\n");
|
|
@@ -8472,7 +8512,7 @@ var viteSearchPlugin = () => {
|
|
|
8472
8512
|
if (config.search.type === "pagefind") {
|
|
8473
8513
|
code.push(
|
|
8474
8514
|
`import config from 'virtual:zudoku-config';`,
|
|
8475
|
-
`import { pagefindSearchPlugin } from "
|
|
8515
|
+
`import { pagefindSearchPlugin } from "${zudokuImportPrefix}/plugins/search-pagefind";`,
|
|
8476
8516
|
`export const configuredSearchPlugin = pagefindSearchPlugin(config.search);`
|
|
8477
8517
|
);
|
|
8478
8518
|
return code.join("\n");
|
|
@@ -8572,7 +8612,7 @@ function vitePlugin() {
|
|
|
8572
8612
|
plugin_api_default(),
|
|
8573
8613
|
viteSearchPlugin(),
|
|
8574
8614
|
plugin_markdown_export_default(),
|
|
8575
|
-
vitePluginSsrCss({ entries: [
|
|
8615
|
+
vitePluginSsrCss({ entries: [getAppServerEntryPath()] }),
|
|
8576
8616
|
viteThemePlugin(),
|
|
8577
8617
|
tailwindcss()
|
|
8578
8618
|
];
|
|
@@ -8952,7 +8992,7 @@ async function getViteConfig(dir, configEnv, options = {}) {
|
|
|
8952
8992
|
build: {
|
|
8953
8993
|
manifest: true,
|
|
8954
8994
|
rolldownOptions: {
|
|
8955
|
-
input:
|
|
8995
|
+
input: getAppClientEntryPath(),
|
|
8956
8996
|
output: shouldProtectChunks ? {
|
|
8957
8997
|
entryFileNames: (chunk) => isProtectedChunk(chunk) ? `${PROTECTED_CHUNK_DIR}/[name]-[hash].js` : "assets/[name]-[hash].js",
|
|
8958
8998
|
chunkFileNames: (chunk) => isProtectedChunk(chunk) ? `${PROTECTED_CHUNK_DIR}/[name]-[hash].js` : "assets/[name]-[hash].js"
|
|
@@ -8973,7 +9013,7 @@ async function getViteConfig(dir, configEnv, options = {}) {
|
|
|
8973
9013
|
copyPublicDir: false,
|
|
8974
9014
|
rolldownOptions: {
|
|
8975
9015
|
logLevel: "warn",
|
|
8976
|
-
input: [
|
|
9016
|
+
input: [getAppServerEntryPath(), config.__meta.configPath]
|
|
8977
9017
|
}
|
|
8978
9018
|
}
|
|
8979
9019
|
}
|
|
@@ -8998,7 +9038,7 @@ async function getViteConfig(dir, configEnv, options = {}) {
|
|
|
8998
9038
|
include: [
|
|
8999
9039
|
"@mdx-js/react",
|
|
9000
9040
|
"react-dom/client",
|
|
9001
|
-
|
|
9041
|
+
zudokuImportPrefix + "/icons",
|
|
9002
9042
|
...process.env.SENTRY_DSN ? ["@sentry/react"] : []
|
|
9003
9043
|
]
|
|
9004
9044
|
},
|
|
@@ -9007,7 +9047,7 @@ async function getViteConfig(dir, configEnv, options = {}) {
|
|
|
9007
9047
|
"/__z/entry.client.tsx",
|
|
9008
9048
|
"**/pagefind.js"
|
|
9009
9049
|
],
|
|
9010
|
-
plugins: [protectedAnnotatorPlugin(), vitePlugin()],
|
|
9050
|
+
plugins: [zudokuSelfReferencePlugin(), protectedAnnotatorPlugin(), vitePlugin()],
|
|
9011
9051
|
future: {
|
|
9012
9052
|
removeServerModuleGraph: "warn",
|
|
9013
9053
|
removeSsrLoadModule: "warn",
|
package/package.json
CHANGED
package/src/vite/config.ts
CHANGED
|
@@ -21,6 +21,10 @@ import { joinUrl } from "../lib/util/joinUrl.js";
|
|
|
21
21
|
import type { SSRAdapter } from "./build.js";
|
|
22
22
|
import { findPackageRoot } from "./package-root.js";
|
|
23
23
|
import vitePlugin from "./plugin.js";
|
|
24
|
+
import {
|
|
25
|
+
zudokuImportPrefix,
|
|
26
|
+
zudokuSelfReferencePlugin,
|
|
27
|
+
} from "./self-reference.js";
|
|
24
28
|
import { protectedAnnotatorPlugin } from "./protected/annotator.js";
|
|
25
29
|
import { getProtectedSourceMatcher } from "./protected/registry.js";
|
|
26
30
|
import { getZuploSystemConfigurations } from "./zuplo.js";
|
|
@@ -201,7 +205,7 @@ export async function getViteConfig(
|
|
|
201
205
|
build: {
|
|
202
206
|
manifest: true,
|
|
203
207
|
rolldownOptions: {
|
|
204
|
-
input:
|
|
208
|
+
input: getAppClientEntryPath(),
|
|
205
209
|
output: shouldProtectChunks
|
|
206
210
|
? {
|
|
207
211
|
entryFileNames: (chunk) =>
|
|
@@ -233,7 +237,7 @@ export async function getViteConfig(
|
|
|
233
237
|
copyPublicDir: false,
|
|
234
238
|
rolldownOptions: {
|
|
235
239
|
logLevel: "warn",
|
|
236
|
-
input: [
|
|
240
|
+
input: [getAppServerEntryPath(), config.__meta.configPath],
|
|
237
241
|
},
|
|
238
242
|
},
|
|
239
243
|
},
|
|
@@ -263,7 +267,7 @@ export async function getViteConfig(
|
|
|
263
267
|
include: [
|
|
264
268
|
"@mdx-js/react",
|
|
265
269
|
"react-dom/client",
|
|
266
|
-
|
|
270
|
+
zudokuImportPrefix + "/icons",
|
|
267
271
|
...(process.env.SENTRY_DSN ? ["@sentry/react"] : []),
|
|
268
272
|
],
|
|
269
273
|
},
|
|
@@ -272,7 +276,7 @@ export async function getViteConfig(
|
|
|
272
276
|
"/__z/entry.client.tsx",
|
|
273
277
|
"**/pagefind.js",
|
|
274
278
|
],
|
|
275
|
-
plugins: [protectedAnnotatorPlugin(), vitePlugin()],
|
|
279
|
+
plugins: [zudokuSelfReferencePlugin(), protectedAnnotatorPlugin(), vitePlugin()],
|
|
276
280
|
future: {
|
|
277
281
|
removeServerModuleGraph: "warn",
|
|
278
282
|
removeSsrLoadModule: "warn",
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
|
+
import { zudokuImportPrefix } from "./self-reference.js";
|
|
2
3
|
import { ZuploEnv } from "../app/env.js";
|
|
3
4
|
import { getCurrentConfig } from "../config/loader.js";
|
|
4
5
|
import { getZuploSystemConfigurations } from "./zuplo.js";
|
|
@@ -28,7 +29,7 @@ const viteApiKeysPlugin = (): Plugin => {
|
|
|
28
29
|
|
|
29
30
|
const code = [
|
|
30
31
|
`import config from "virtual:zudoku-config";`,
|
|
31
|
-
`import { apiKeyPlugin } from "
|
|
32
|
+
`import { apiKeyPlugin } from "${zudokuImportPrefix}/plugins/api-keys";`,
|
|
32
33
|
`export const configuredApiKeysPlugin = apiKeyPlugin({
|
|
33
34
|
...config.apiKeys,
|
|
34
35
|
isZuplo: ${ZuploEnv.isZuplo},
|
package/src/vite/plugin-api.ts
CHANGED
|
@@ -3,6 +3,7 @@ import path from "node:path";
|
|
|
3
3
|
import { deepEqual } from "fast-equals";
|
|
4
4
|
import { type Plugin, runnerImport } from "vite";
|
|
5
5
|
import { parse as parseYaml } from "yaml";
|
|
6
|
+
import { zudokuImportPrefix } from "./self-reference.js";
|
|
6
7
|
import { ZuploEnv } from "../app/env.js";
|
|
7
8
|
import { getZudokuRootDir } from "../cli/common/package-json.js";
|
|
8
9
|
import { type ConfigWithMeta, getCurrentConfig } from "../config/loader.js";
|
|
@@ -238,7 +239,7 @@ const viteApiPlugin = async (): Promise<Plugin> => {
|
|
|
238
239
|
];
|
|
239
240
|
|
|
240
241
|
if (config.apis) {
|
|
241
|
-
code.push(
|
|
242
|
+
code.push(`import { openApiPlugin } from "${zudokuImportPrefix}/plugins/openapi";`);
|
|
242
243
|
code.push(
|
|
243
244
|
`const apis = Array.isArray(config.apis) ? config.apis : [config.apis]`,
|
|
244
245
|
);
|
|
@@ -390,7 +391,7 @@ const viteApiPlugin = async (): Promise<Plugin> => {
|
|
|
390
391
|
|
|
391
392
|
if (config.catalogs) {
|
|
392
393
|
code.push(
|
|
393
|
-
|
|
394
|
+
`import { apiCatalogPlugin } from "${zudokuImportPrefix}/plugins/api-catalog";`,
|
|
394
395
|
);
|
|
395
396
|
|
|
396
397
|
const catalogs = ensureArray(config.catalogs);
|
package/src/vite/plugin-auth.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
|
+
import { zudokuImportPrefix } from "./self-reference.js";
|
|
2
3
|
import { getCurrentConfig } from "../config/loader.js";
|
|
3
4
|
|
|
4
5
|
const viteAuthPlugin = (): Plugin => {
|
|
@@ -25,7 +26,7 @@ const viteAuthPlugin = (): Plugin => {
|
|
|
25
26
|
...${JSON.stringify(config.authentication, null, 2)},
|
|
26
27
|
basePath: ${config.basePath ? JSON.stringify(config.basePath) : "undefined"},
|
|
27
28
|
};`,
|
|
28
|
-
`import authProvider from "
|
|
29
|
+
`import authProvider from "${zudokuImportPrefix}/auth/${config.authentication.type}";`,
|
|
29
30
|
`export const configuredAuthProvider = authProvider(config);`,
|
|
30
31
|
].join("\n");
|
|
31
32
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
|
+
import { zudokuImportPrefix } from "./self-reference.js";
|
|
2
3
|
import { getCurrentConfig } from "../config/loader.js";
|
|
3
4
|
|
|
4
5
|
const viteCustomPagesPlugin = (): Plugin => {
|
|
@@ -21,7 +22,7 @@ const viteCustomPagesPlugin = (): Plugin => {
|
|
|
21
22
|
|
|
22
23
|
const code = [
|
|
23
24
|
`import config from "virtual:zudoku-config";`,
|
|
24
|
-
`import { customPagesPlugin } from "
|
|
25
|
+
`import { customPagesPlugin } from "${zudokuImportPrefix}/plugins/custom-pages";`,
|
|
25
26
|
`export const configuredCustomPagesPlugin = customPagesPlugin(config.navigation);`,
|
|
26
27
|
];
|
|
27
28
|
|
package/src/vite/plugin-docs.ts
CHANGED
|
@@ -2,6 +2,7 @@ import path from "node:path";
|
|
|
2
2
|
import { glob } from "glob";
|
|
3
3
|
import globParent from "glob-parent";
|
|
4
4
|
import type { Plugin } from "vite";
|
|
5
|
+
import { zudokuImportPrefix } from "./self-reference.js";
|
|
5
6
|
import { type ConfigWithMeta, getCurrentConfig } from "../config/loader.js";
|
|
6
7
|
import {
|
|
7
8
|
type NavigationItem,
|
|
@@ -141,7 +142,7 @@ const viteDocsPlugin = (): Plugin => {
|
|
|
141
142
|
}
|
|
142
143
|
|
|
143
144
|
const code = [
|
|
144
|
-
|
|
145
|
+
`import { markdownPlugin } from "${zudokuImportPrefix}/plugins/markdown";`,
|
|
145
146
|
];
|
|
146
147
|
|
|
147
148
|
// Glob markdown files and resolve custom navigation paths
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { stringify } from "javascript-stringify";
|
|
2
2
|
import { isElement } from "react-is";
|
|
3
3
|
import type { Plugin, ViteDevServer } from "vite";
|
|
4
|
+
import { zudokuImportPrefix } from "./self-reference.js";
|
|
4
5
|
import { getCurrentConfig } from "../config/loader.js";
|
|
5
6
|
import { IconNames } from "../config/validators/icon-types.js";
|
|
6
7
|
import { NavigationResolver } from "../config/validators/NavigationSchema.js";
|
|
@@ -92,7 +93,7 @@ export const viteNavigationPlugin = (): Plugin => {
|
|
|
92
93
|
|
|
93
94
|
const importStatement =
|
|
94
95
|
collectedIcons.size > 0
|
|
95
|
-
? `import { ${[...collectedIcons].join(", ")} } from "
|
|
96
|
+
? `import { ${[...collectedIcons].join(", ")} } from "${zudokuImportPrefix}/icons";\n`
|
|
96
97
|
: "";
|
|
97
98
|
|
|
98
99
|
return [
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Plugin } from "vite";
|
|
2
|
+
import { zudokuImportPrefix } from "./self-reference.js";
|
|
2
3
|
import { getCurrentConfig } from "../config/loader.js";
|
|
3
4
|
|
|
4
5
|
export const viteSearchPlugin = (): Plugin => {
|
|
@@ -26,7 +27,7 @@ export const viteSearchPlugin = (): Plugin => {
|
|
|
26
27
|
if (config.search.type === "inkeep") {
|
|
27
28
|
code.push(
|
|
28
29
|
`import config from 'virtual:zudoku-config';`,
|
|
29
|
-
`import { inkeepSearchPlugin } from "
|
|
30
|
+
`import { inkeepSearchPlugin } from "${zudokuImportPrefix}/plugins/search-inkeep";`,
|
|
30
31
|
`export const configuredSearchPlugin = inkeepSearchPlugin(config.search);`,
|
|
31
32
|
);
|
|
32
33
|
|
|
@@ -36,7 +37,7 @@ export const viteSearchPlugin = (): Plugin => {
|
|
|
36
37
|
if (config.search.type === "pagefind") {
|
|
37
38
|
code.push(
|
|
38
39
|
`import config from 'virtual:zudoku-config';`,
|
|
39
|
-
`import { pagefindSearchPlugin } from "
|
|
40
|
+
`import { pagefindSearchPlugin } from "${zudokuImportPrefix}/plugins/search-pagefind";`,
|
|
40
41
|
`export const configuredSearchPlugin = pagefindSearchPlugin(config.search);`,
|
|
41
42
|
);
|
|
42
43
|
|
package/src/vite/plugin.ts
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
|
+
import path from "node:path";
|
|
1
2
|
import tailwindcss from "@ohos-ports/tailwindcss-vite";
|
|
2
3
|
import react from "@vitejs/plugin-react";
|
|
3
4
|
import type { PluginOption } from "vite";
|
|
4
5
|
import { vitePluginSsrCss } from "./css/plugin.js";
|
|
6
|
+
import { getZudokuRootDir } from "../cli/common/package-json.js";
|
|
5
7
|
import viteApiKeysPlugin from "./plugin-api-keys.js";
|
|
6
8
|
import viteApiPlugin from "./plugin-api.js";
|
|
7
9
|
import viteAuthPlugin from "./plugin-auth.js";
|
|
@@ -33,7 +35,11 @@ export default function vitePlugin(): PluginOption {
|
|
|
33
35
|
viteApiPlugin(),
|
|
34
36
|
viteSearchPlugin(),
|
|
35
37
|
viteMarkdownExportPlugin(),
|
|
36
|
-
vitePluginSsrCss({
|
|
38
|
+
vitePluginSsrCss({
|
|
39
|
+
entries: [
|
|
40
|
+
path.posix.join(getZudokuRootDir(), "src/app/entry.server.tsx"),
|
|
41
|
+
],
|
|
42
|
+
}),
|
|
37
43
|
viteThemePlugin(),
|
|
38
44
|
tailwindcss(),
|
|
39
45
|
];
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import path from "node:path";
|
|
2
|
+
import { fileURLToPath } from "node:url";
|
|
3
|
+
import type { Plugin } from "vite";
|
|
4
|
+
import { getZudokuRootDir } from "../cli/common/package-json.js";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Bare specifier under which THIS package instance is visible to the consumer's
|
|
8
|
+
* vite resolver (plain node_modules lookup). Node's import.meta.resolve honors
|
|
9
|
+
* package self-reference by package.json "name" regardless of the installed
|
|
10
|
+
* directory name, so we probe "zudoku" first (npm-alias installs put this package
|
|
11
|
+
* at node_modules/zudoku) and fall back to the canonical "@ohos-ports/zudoku".
|
|
12
|
+
*/
|
|
13
|
+
export const zudokuImportPrefix = (() => {
|
|
14
|
+
const root = getZudokuRootDir() + path.posix.sep;
|
|
15
|
+
for (const name of ["zudoku", "@ohos-ports/zudoku"]) {
|
|
16
|
+
try {
|
|
17
|
+
if (
|
|
18
|
+
fileURLToPath(import.meta.resolve(name + "/package.json")).startsWith(
|
|
19
|
+
root,
|
|
20
|
+
)
|
|
21
|
+
) {
|
|
22
|
+
return name;
|
|
23
|
+
}
|
|
24
|
+
} catch {}
|
|
25
|
+
}
|
|
26
|
+
return "@ohos-ports/zudoku";
|
|
27
|
+
})();
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Vite's resolver has no Node-style package self-reference: bare
|
|
31
|
+
* "zudoku"/"@ohos-ports/zudoku" specifiers only resolve when a node_modules
|
|
32
|
+
* directory of that exact name exists. Route them through import.meta.resolve
|
|
33
|
+
* (which honors the package.json "name" self-reference) and accept the result
|
|
34
|
+
* only when it points into this package instance. Makes shipped source work
|
|
35
|
+
* under both canonical (@ohos-ports/zudoku) and npm-alias ("zudoku") installs.
|
|
36
|
+
*/
|
|
37
|
+
export const zudokuSelfReferencePlugin = (): Plugin => {
|
|
38
|
+
const root = getZudokuRootDir() + path.posix.sep;
|
|
39
|
+
return {
|
|
40
|
+
name: "zudoku:self-reference",
|
|
41
|
+
enforce: "pre",
|
|
42
|
+
resolveId(id) {
|
|
43
|
+
const queryMatch = id.match(/[?#].*$/);
|
|
44
|
+
const query = queryMatch ? queryMatch[0] : "";
|
|
45
|
+
const bare = query ? id.slice(0, id.length - query.length) : id;
|
|
46
|
+
if (!/^(?:@ohos-ports\/)?zudoku(\/.*)?$/.test(bare)) {
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
try {
|
|
50
|
+
const resolved = fileURLToPath(import.meta.resolve(bare));
|
|
51
|
+
if (resolved.startsWith(root)) {
|
|
52
|
+
return resolved + query;
|
|
53
|
+
}
|
|
54
|
+
} catch {}
|
|
55
|
+
return null;
|
|
56
|
+
},
|
|
57
|
+
};
|
|
58
|
+
};
|