@nuxt/bridge-edge 3.0.0-27404660.0f9bcbf → 3.0.0-27405808.7825e2a

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.
@@ -1,13 +1,14 @@
1
1
  import { createRequire } from 'module';
2
- import { useNuxt, addPluginTemplate, resolveModule, addTemplate, addVitePlugin, addWebpackPlugin, extendWebpackConfig, resolveFiles, defineNuxtModule, resolveAlias, installModule, isNuxt3, addPlugin, nuxtCtx, checkNuxtCompatibility } from '@nuxt/kit';
2
+ import { useNuxt, addPluginTemplate, resolveModule, addTemplate, resolveAlias, addVitePlugin, addWebpackPlugin, extendWebpackConfig, resolveFiles, defineNuxtModule, installModule, isNuxt3, addPlugin, nuxtCtx, checkNuxtCompatibility } from '@nuxt/kit';
3
3
  import fs, { existsSync, promises } from 'fs';
4
4
  import fetch from 'node-fetch';
5
- import { stringifyQuery, parseURL, parseQuery } from 'ufo';
5
+ import { joinURL, stringifyQuery, parseURL, parseQuery } from 'ufo';
6
6
  import { dirname, resolve, isAbsolute, relative, join as join$1, parse as parse$1, normalize } from 'pathe';
7
7
  import { getNitroContext, resolveMiddleware, scanMiddleware, writeTypes, build, prepare, generate, wpfs, createDevServer } from '@nuxt/nitro';
8
8
  import { fileURLToPath } from 'url';
9
9
  import { join } from 'path';
10
- import { genDynamicImport, genExport, genString, genImport } from 'knitwork';
10
+ import { genDynamicImport, genString, genExport, genImport } from 'knitwork';
11
+ import escapeRE from 'escape-string-regexp';
11
12
  import crypto from 'crypto';
12
13
  import { createUnplugin } from 'unplugin';
13
14
  import { parse } from 'acorn';
@@ -290,9 +291,13 @@ function createNuxt2DevServer(nitroContext) {
290
291
  if (!listener) {
291
292
  throw new Error("There is no server listener to call `server.renderRoute()`");
292
293
  }
293
- const html = await fetch(listener.url + route, {
294
+ const res = await fetch(joinURL(listener.url, route), {
294
295
  headers: { "nuxt-render-context": stringifyQuery(renderContext) }
295
- }).then((r) => r.text());
296
+ });
297
+ const html = await res.text();
298
+ if (!res.ok) {
299
+ return { html, error: res.statusText };
300
+ }
296
301
  return { html };
297
302
  }
298
303
  return {
@@ -320,6 +325,25 @@ export {}
320
325
  `
321
326
  };
322
327
 
328
+ const adHocModules = ["router", "pages", "auto-imports", "meta", "components"];
329
+ const schemaTemplate = {
330
+ filename: "types/schema.d.ts",
331
+ getContents: ({ nuxt }) => {
332
+ const moduleInfo = nuxt.options._installedModules.map((m) => ({
333
+ ...m.meta || {},
334
+ importName: m.entryPath || m.meta?.name
335
+ })).filter((m) => m.configKey && m.name && !adHocModules.includes(m.name));
336
+ return [
337
+ "import { NuxtModule } from '@nuxt/schema'",
338
+ "declare module '@nuxt/schema' {",
339
+ " interface NuxtConfig {",
340
+ ...moduleInfo.filter(Boolean).map((meta) => ` [${genString(meta.configKey)}]?: typeof ${genDynamicImport(meta.importName, { wrapper: false })}.default extends NuxtModule<infer O> ? Partial<O> : Record<string, any>`),
341
+ " }",
342
+ "}"
343
+ ].join("\n");
344
+ }
345
+ };
346
+
323
347
  function setupAppBridge(_options) {
324
348
  const nuxt = useNuxt();
325
349
  nuxt.options.alias["#app"] = resolve(distDir$1, "runtime/index.mjs");
@@ -344,6 +368,13 @@ function setupAppBridge(_options) {
344
368
  nuxt.hook("prepare:types", ({ references }) => {
345
369
  references.push({ path: resolve(nuxt.options.buildDir, "types/components.d.ts") });
346
370
  });
371
+ nuxt.hook("modules:done", async (container) => {
372
+ nuxt.options._installedModules = await Promise.all(Object.values(container.requiredModules).map(async (m) => ({
373
+ meta: await m.handler.getMeta?.(),
374
+ entryPath: resolveAlias(m.src, nuxt.options.alias)
375
+ })));
376
+ addTemplate(schemaTemplate);
377
+ });
347
378
  nuxt.options.alias["vue2-bridge"] = resolve(distDir$1, "runtime/vue2-bridge.mjs");
348
379
  for (const alias of [
349
380
  "vue",
@@ -762,18 +793,6 @@ async function scanForComposables(dir, autoImports) {
762
793
  }));
763
794
  }
764
795
 
765
- function escapeStringRegexp(string) {
766
- if (typeof string !== 'string') {
767
- throw new TypeError('Expected a string');
768
- }
769
-
770
- // Escape characters with special meaning either inside or outside character sets.
771
- // Use a simple backslash escape when it’s always valid, and a `\xnn` escape when the simpler form would be disallowed by Unicode patterns’ stricter grammar.
772
- return string
773
- .replace(/[|\\{}()[\]^$+*?.]/g, '\\$&')
774
- .replace(/-/g, '\\x2d');
775
- }
776
-
777
796
  function createAutoImportContext(opts) {
778
797
  return {
779
798
  autoImports: [],
@@ -795,7 +814,7 @@ function updateAutoImportContext(ctx) {
795
814
  }
796
815
  }
797
816
  ctx.autoImports = ctx.autoImports.filter((i) => i.disabled !== true);
798
- ctx.matchRE = new RegExp(`\\b(${ctx.autoImports.map((i) => escapeStringRegexp(i.as)).join("|")})\\b`, "g");
817
+ ctx.matchRE = new RegExp(`\\b(${ctx.autoImports.map((i) => escapeRE(i.as)).join("|")})\\b`, "g");
799
818
  ctx.map.clear();
800
819
  for (const autoImport of ctx.autoImports) {
801
820
  ctx.map.set(autoImport.as, autoImport);
@@ -820,15 +839,6 @@ const autoImports = defineNuxtModule({
820
839
  await nuxt.callHook("autoImports:sources", options.sources);
821
840
  options.sources = options.sources.filter((source) => source.disabled !== true);
822
841
  const ctx = createAutoImportContext(options);
823
- for (const source of options.sources) {
824
- for (const importName of source.names) {
825
- if (typeof importName === "string") {
826
- ctx.autoImports.push({ name: importName, as: importName, from: source.from });
827
- } else {
828
- ctx.autoImports.push({ name: importName.name, as: importName.as || importName.name, from: source.from });
829
- }
830
- }
831
- }
832
842
  let composablesDirs = [
833
843
  join$1(nuxt.options.srcDir, "composables"),
834
844
  ...options.dirs
@@ -858,15 +868,16 @@ export default () => {};`;
858
868
  addVitePlugin(TransformPlugin.vite(ctx));
859
869
  addWebpackPlugin(TransformPlugin.webpack(ctx));
860
870
  }
861
- const updateAutoImports = async () => {
871
+ const regenerateAutoImports = async () => {
872
+ ctx.autoImports = options.sources.flatMap((source) => source.names.map((importName) => typeof importName === "string" ? { name: importName, as: importName, from: source.from } : { name: importName.name, as: importName.as || importName.name, from: source.from }));
862
873
  for (const composablesDir of composablesDirs) {
863
874
  await scanForComposables(composablesDir, ctx.autoImports);
864
875
  }
865
876
  await nuxt.callHook("autoImports:extend", ctx.autoImports);
866
877
  updateAutoImportContext(ctx);
867
- generateDts(ctx);
868
878
  };
869
- await updateAutoImports();
879
+ await regenerateAutoImports();
880
+ addDeclarationTemplates(ctx);
870
881
  nuxt.hook("prepare:types", ({ references }) => {
871
882
  references.push({ path: resolve(nuxt.options.buildDir, "types/auto-imports.d.ts") });
872
883
  references.push({ path: resolve(nuxt.options.buildDir, "types/imports.d.ts") });
@@ -874,12 +885,13 @@ export default () => {};`;
874
885
  nuxt.hook("builder:watch", async (_, path) => {
875
886
  const _resolved = resolve(nuxt.options.srcDir, path);
876
887
  if (composablesDirs.find((dir) => _resolved.startsWith(dir))) {
877
- await updateAutoImports();
888
+ await regenerateAutoImports();
889
+ await nuxt.callHook("builder:generateApp");
878
890
  }
879
891
  });
880
892
  }
881
893
  });
882
- function generateDts(ctx) {
894
+ function addDeclarationTemplates(ctx) {
883
895
  const nuxt = useNuxt();
884
896
  const resolved = {};
885
897
  const r = (id) => {
@@ -896,12 +908,10 @@ function generateDts(ctx) {
896
908
  };
897
909
  addTemplate({
898
910
  filename: "types/imports.d.ts",
899
- write: true,
900
911
  getContents: () => toExports(ctx.autoImports)
901
912
  });
902
913
  addTemplate({
903
914
  filename: "types/auto-imports.d.ts",
904
- write: true,
905
915
  getContents: () => `// Generated by auto imports
906
916
  declare global {
907
917
  ${ctx.autoImports.map((i) => ` const ${i.as}: typeof ${genDynamicImport(r(i.from), { wrapper: false })}['${i.name}']`).join("\n")}
@@ -944,13 +954,12 @@ function setupTypescript() {
944
954
  const nuxt = useNuxt();
945
955
  nuxt.options.extensions.push(...extensions);
946
956
  nuxt.options.build.additionalExtensions.push(...extensions);
947
- const _require = createRequire(import.meta.url);
948
- const babelPlugin = _require.resolve("@babel/plugin-transform-typescript");
949
957
  nuxt.options.build.babel.plugins = nuxt.options.build.babel.plugins || [];
950
958
  if (nuxt.options.buildModules.includes("@nuxt/typescript-build")) {
951
959
  throw new Error("Please remove `@nuxt/typescript-build` from `buildModules` or set `bridge.typescript: false` to avoid conflict with bridge.");
952
960
  }
953
- nuxt.options.build.babel.plugins.unshift(babelPlugin);
961
+ const _require = createRequire(import.meta.url);
962
+ nuxt.options.build.babel.plugins.unshift(_require.resolve("@babel/plugin-proposal-optional-chaining"), _require.resolve("@babel/plugin-proposal-nullish-coalescing-operator"), _require.resolve("@babel/plugin-transform-typescript"));
954
963
  extendWebpackConfig((config) => {
955
964
  config.resolve.extensions.push(...extensions.map((e) => `.${e}`));
956
965
  const babelRule = config.module.rules.find((rule) => rule.test?.test("test.js"));
@@ -4,7 +4,7 @@ import hash from 'hash-sum';
4
4
  import { resolve } from 'pathe';
5
5
  import { genImport, genObjectFromRawEntries } from 'knitwork';
6
6
 
7
- const version = "3.0.0-27404660.0f9bcbf";
7
+ const version = "3.0.0-27405808.7825e2a";
8
8
 
9
9
  const middlewareTemplate = {
10
10
  filename: "middleware.js",
@@ -20,6 +20,7 @@ import '@nuxt/kit';
20
20
  import 'node-fetch';
21
21
  import '@nuxt/nitro';
22
22
  import 'path';
23
+ import 'escape-string-regexp';
23
24
  import 'unplugin';
24
25
  import 'acorn';
25
26
  import 'magic-string';
package/dist/module.mjs CHANGED
@@ -9,6 +9,7 @@ import '@nuxt/nitro';
9
9
  import 'url';
10
10
  import 'path';
11
11
  import 'knitwork';
12
+ import 'escape-string-regexp';
12
13
  import 'crypto';
13
14
  import 'unplugin';
14
15
  import 'acorn';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxt/bridge-edge",
3
- "version": "3.0.0-27404660.0f9bcbf",
3
+ "version": "3.0.0-27405808.7825e2a",
4
4
  "repository": "nuxt/framework",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -18,11 +18,13 @@
18
18
  "prepack": "unbuild"
19
19
  },
20
20
  "dependencies": {
21
+ "@babel/plugin-proposal-nullish-coalescing-operator": "^7.16.7",
22
+ "@babel/plugin-proposal-optional-chaining": "^7.16.7",
21
23
  "@babel/plugin-transform-typescript": "^7.16.8",
22
- "@nuxt/kit": "npm:@nuxt/kit-edge@3.0.0-27404660.0f9bcbf",
23
- "@nuxt/nitro": "npm:@nuxt/nitro-edge@3.0.0-27404660.0f9bcbf",
24
+ "@nuxt/kit": "npm:@nuxt/kit-edge@3.0.0-27405808.7825e2a",
25
+ "@nuxt/nitro": "npm:@nuxt/nitro-edge@3.0.0-27405808.7825e2a",
24
26
  "@nuxt/postcss8": "^1.1.3",
25
- "@nuxt/schema": "npm:@nuxt/schema-edge@3.0.0-27404660.0f9bcbf",
27
+ "@nuxt/schema": "npm:@nuxt/schema-edge@3.0.0-27405808.7825e2a",
26
28
  "@vitejs/plugin-legacy": "^1.6.4",
27
29
  "@vue/composition-api": "^1.4.6",
28
30
  "@vueuse/head": "^0.7.5",
@@ -31,7 +33,8 @@
31
33
  "cookie-es": "^0.5.0",
32
34
  "defu": "^5.0.1",
33
35
  "destr": "^1.1.0",
34
- "enhanced-resolve": "^5.8.3",
36
+ "enhanced-resolve": "^5.9.0",
37
+ "escape-string-regexp": "^5.0.0",
35
38
  "estree-walker": "^3.0.1",
36
39
  "externality": "^0.1.6",
37
40
  "fs-extra": "^10.0.0",
@@ -43,7 +46,7 @@
43
46
  "mlly": "^0.4.2",
44
47
  "murmurhash-es": "^0.1.1",
45
48
  "node-fetch": "^3.2.0",
46
- "nuxi": "npm:nuxi-edge@3.0.0-27404660.0f9bcbf",
49
+ "nuxi": "npm:nuxi-edge@3.0.0-27405808.7825e2a",
47
50
  "p-debounce": "^4.0.0",
48
51
  "pathe": "^0.2.0",
49
52
  "postcss": "^8",
@@ -55,7 +58,7 @@
55
58
  "semver": "^7.3.5",
56
59
  "ufo": "^0.7.9",
57
60
  "unplugin": "^0.3.2",
58
- "unplugin-vue2-script-setup": "0.9.1",
61
+ "unplugin-vue2-script-setup": "0.9.2",
59
62
  "vite": "^2.7.13",
60
63
  "vite-plugin-vue2": "^1.9.3",
61
64
  "vue-template-compiler": "^2.6.14"