@nuxt/bridge-edge 0.0.0-27215666.041b60f → 0.0.0-27219596.a2da8a0
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/module.cjs +116 -2
- package/dist/module.mjs +116 -3
- package/package.json +6 -5
package/dist/module.cjs
CHANGED
|
@@ -11,12 +11,16 @@ const unplugin = require('unplugin');
|
|
|
11
11
|
const acorn = require('acorn');
|
|
12
12
|
const MagicString = require('magic-string');
|
|
13
13
|
const estreeWalker = require('estree-walker');
|
|
14
|
+
const fs = require('fs');
|
|
15
|
+
const util = require('util');
|
|
16
|
+
const enhancedResolve = require('enhanced-resolve');
|
|
14
17
|
|
|
15
18
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e["default"] : e; }
|
|
16
19
|
|
|
17
20
|
const fetch__default = /*#__PURE__*/_interopDefaultLegacy(fetch);
|
|
18
21
|
const crypto__default = /*#__PURE__*/_interopDefaultLegacy(crypto);
|
|
19
22
|
const MagicString__default = /*#__PURE__*/_interopDefaultLegacy(MagicString);
|
|
23
|
+
const fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
|
|
20
24
|
|
|
21
25
|
class AsyncLoadingPlugin {
|
|
22
26
|
apply(compiler) {
|
|
@@ -363,7 +367,13 @@ function setupCAPIBridge(_options) {
|
|
|
363
367
|
if (nuxt.options.buildModules.find((m) => m === "@nuxtjs/composition-api" || m === "@nuxtjs/composition-api/module")) {
|
|
364
368
|
throw new Error("Please remove `@nuxtjs/composition-api` from `buildModules` to avoid conflict with bridge.");
|
|
365
369
|
}
|
|
366
|
-
|
|
370
|
+
const vueCapiEntry = require.resolve("@vue/composition-api/dist/vue-composition-api.mjs");
|
|
371
|
+
nuxt.options.alias["@vue/composition-api/dist/vue-composition-api.common.js"] = vueCapiEntry;
|
|
372
|
+
nuxt.options.alias["@vue/composition-api/dist/vue-composition-api.common.prod.js"] = vueCapiEntry;
|
|
373
|
+
nuxt.options.alias["@vue/composition-api/dist/vue-composition-api.esm.js"] = vueCapiEntry;
|
|
374
|
+
nuxt.options.alias["@vue/composition-api/dist/vue-composition-api.js"] = vueCapiEntry;
|
|
375
|
+
nuxt.options.alias["@vue/composition-api/dist/vue-composition-api.mjs"] = vueCapiEntry;
|
|
376
|
+
nuxt.options.alias["@vue/composition-api"] = vueCapiEntry;
|
|
367
377
|
const capiPluginPath = pathe.resolve(distDir, "runtime/capi.plugin.mjs");
|
|
368
378
|
kit.addPluginTemplate({ filename: "capi.plugin.mjs", src: capiPluginPath });
|
|
369
379
|
const appPlugin = kit.addPluginTemplate(pathe.resolve(distDir, "runtime/app.plugin.mjs"));
|
|
@@ -380,6 +390,106 @@ function setupCAPIBridge(_options) {
|
|
|
380
390
|
kit.addWebpackPlugin(KeyPlugin.webpack());
|
|
381
391
|
}
|
|
382
392
|
|
|
393
|
+
function isObject(val) {
|
|
394
|
+
return val !== null && typeof val === "object";
|
|
395
|
+
}
|
|
396
|
+
function _defu(baseObj, defaults, namespace = ".", merger) {
|
|
397
|
+
if (!isObject(defaults)) {
|
|
398
|
+
return _defu(baseObj, {}, namespace, merger);
|
|
399
|
+
}
|
|
400
|
+
const obj = Object.assign({}, defaults);
|
|
401
|
+
for (const key in baseObj) {
|
|
402
|
+
if (key === "__proto__" || key === "constructor") {
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
const val = baseObj[key];
|
|
406
|
+
if (val === null || val === void 0) {
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
if (merger && merger(obj, key, val, namespace)) {
|
|
410
|
+
continue;
|
|
411
|
+
}
|
|
412
|
+
if (Array.isArray(val) && Array.isArray(obj[key])) {
|
|
413
|
+
obj[key] = obj[key].concat(val);
|
|
414
|
+
} else if (isObject(val) && isObject(obj[key])) {
|
|
415
|
+
obj[key] = _defu(val, obj[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
|
|
416
|
+
} else {
|
|
417
|
+
obj[key] = val;
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
return obj;
|
|
421
|
+
}
|
|
422
|
+
function extend(merger) {
|
|
423
|
+
return (...args) => args.reduce((p, c) => _defu(p, c, "", merger), {});
|
|
424
|
+
}
|
|
425
|
+
const defu = extend();
|
|
426
|
+
defu.fn = extend((obj, key, currentValue, _namespace) => {
|
|
427
|
+
if (typeof obj[key] !== "undefined" && typeof currentValue === "function") {
|
|
428
|
+
obj[key] = currentValue(obj[key]);
|
|
429
|
+
return true;
|
|
430
|
+
}
|
|
431
|
+
});
|
|
432
|
+
defu.arrayFn = extend((obj, key, currentValue, _namespace) => {
|
|
433
|
+
if (Array.isArray(obj[key]) && typeof currentValue === "function") {
|
|
434
|
+
obj[key] = currentValue(obj[key]);
|
|
435
|
+
return true;
|
|
436
|
+
}
|
|
437
|
+
});
|
|
438
|
+
defu.extend = extend;
|
|
439
|
+
|
|
440
|
+
const DEFAULTS = {
|
|
441
|
+
fileSystem: new enhancedResolve.CachedInputFileSystem(fs__default, 4e3),
|
|
442
|
+
extensions: [".ts", ".mjs", ".cjs", ".js", ".json"],
|
|
443
|
+
mainFields: ["module", "main"]
|
|
444
|
+
};
|
|
445
|
+
const createResolver = (resolveOptions) => {
|
|
446
|
+
const options = defu(resolveOptions, DEFAULTS);
|
|
447
|
+
const resolver = enhancedResolve.ResolverFactory.createResolver(options);
|
|
448
|
+
const root = options.roots?.[0] || ".";
|
|
449
|
+
const promisifiedResolve = util.promisify(resolver.resolve.bind(resolver));
|
|
450
|
+
const resolve = (id, importer) => promisifiedResolve({}, importer || root, id, {});
|
|
451
|
+
return { resolve, resolver };
|
|
452
|
+
};
|
|
453
|
+
class EnhancedResolverPlugin {
|
|
454
|
+
constructor(options) {
|
|
455
|
+
this.resolver = createResolver(options);
|
|
456
|
+
}
|
|
457
|
+
apply(defaultResolver) {
|
|
458
|
+
const enhancedResolver = this.resolver;
|
|
459
|
+
defaultResolver.getHook("resolve").tapPromise("EnhancedResolverPlugin", async (request) => {
|
|
460
|
+
const id = request.request;
|
|
461
|
+
if (!id || !defaultResolver.isModule(id)) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
const importer = request.context?.issuer;
|
|
465
|
+
try {
|
|
466
|
+
const result = await enhancedResolver.resolve(id, importer);
|
|
467
|
+
if (!result) {
|
|
468
|
+
return;
|
|
469
|
+
}
|
|
470
|
+
request.path = result;
|
|
471
|
+
return request;
|
|
472
|
+
} catch {
|
|
473
|
+
}
|
|
474
|
+
});
|
|
475
|
+
}
|
|
476
|
+
}
|
|
477
|
+
function setupBetterResolve() {
|
|
478
|
+
const nuxt = kit.useNuxt();
|
|
479
|
+
kit.extendWebpackConfig((config) => {
|
|
480
|
+
const isServer = config.name === "server";
|
|
481
|
+
config.resolve = config.resolve || {};
|
|
482
|
+
config.resolve.plugins = config.resolve.plugins || [];
|
|
483
|
+
config.resolve.plugins.push(new EnhancedResolverPlugin({
|
|
484
|
+
conditionNames: ["import", ...isServer ? ["node"] : []],
|
|
485
|
+
alias: config.resolve.alias,
|
|
486
|
+
modules: config.resolve.modules,
|
|
487
|
+
plugins: config.resolve.plugins,
|
|
488
|
+
roots: config.resolve.roots || [nuxt.options.rootDir]
|
|
489
|
+
}));
|
|
490
|
+
});
|
|
491
|
+
}
|
|
492
|
+
|
|
383
493
|
const module$1 = kit.defineNuxtModule({
|
|
384
494
|
name: "nuxt-bridge",
|
|
385
495
|
configKey: "bridge",
|
|
@@ -389,7 +499,8 @@ const module$1 = kit.defineNuxtModule({
|
|
|
389
499
|
app: {},
|
|
390
500
|
capi: {},
|
|
391
501
|
postcss8: true,
|
|
392
|
-
swc: true
|
|
502
|
+
swc: true,
|
|
503
|
+
resolve: true
|
|
393
504
|
},
|
|
394
505
|
async setup(opts, nuxt) {
|
|
395
506
|
if (opts.nitro) {
|
|
@@ -413,6 +524,9 @@ const module$1 = kit.defineNuxtModule({
|
|
|
413
524
|
if (opts.swc) {
|
|
414
525
|
await kit.installModule(nuxt, require.resolve("nuxt-swc"));
|
|
415
526
|
}
|
|
527
|
+
if (opts.resolve) {
|
|
528
|
+
setupBetterResolve();
|
|
529
|
+
}
|
|
416
530
|
}
|
|
417
531
|
});
|
|
418
532
|
|
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useNuxt, addPluginTemplate, resolveModule, addPlugin, addVitePlugin, addWebpackPlugin, defineNuxtModule, installModule } from '@nuxt/kit';
|
|
1
|
+
import { useNuxt, addPluginTemplate, resolveModule, addPlugin, addVitePlugin, addWebpackPlugin, extendWebpackConfig, defineNuxtModule, installModule } from '@nuxt/kit';
|
|
2
2
|
import fetch from 'node-fetch';
|
|
3
3
|
import { stringifyQuery, parseURL, parseQuery } from 'ufo';
|
|
4
4
|
import { resolve } from 'pathe';
|
|
@@ -9,6 +9,9 @@ import { createUnplugin } from 'unplugin';
|
|
|
9
9
|
import { parse } from 'acorn';
|
|
10
10
|
import MagicString from 'magic-string';
|
|
11
11
|
import { walk } from 'estree-walker';
|
|
12
|
+
import fs from 'fs';
|
|
13
|
+
import { promisify } from 'util';
|
|
14
|
+
import { CachedInputFileSystem, ResolverFactory } from 'enhanced-resolve';
|
|
12
15
|
|
|
13
16
|
class AsyncLoadingPlugin {
|
|
14
17
|
apply(compiler) {
|
|
@@ -355,7 +358,13 @@ function setupCAPIBridge(_options) {
|
|
|
355
358
|
if (nuxt.options.buildModules.find((m) => m === "@nuxtjs/composition-api" || m === "@nuxtjs/composition-api/module")) {
|
|
356
359
|
throw new Error("Please remove `@nuxtjs/composition-api` from `buildModules` to avoid conflict with bridge.");
|
|
357
360
|
}
|
|
358
|
-
|
|
361
|
+
const vueCapiEntry = require.resolve("@vue/composition-api/dist/vue-composition-api.mjs");
|
|
362
|
+
nuxt.options.alias["@vue/composition-api/dist/vue-composition-api.common.js"] = vueCapiEntry;
|
|
363
|
+
nuxt.options.alias["@vue/composition-api/dist/vue-composition-api.common.prod.js"] = vueCapiEntry;
|
|
364
|
+
nuxt.options.alias["@vue/composition-api/dist/vue-composition-api.esm.js"] = vueCapiEntry;
|
|
365
|
+
nuxt.options.alias["@vue/composition-api/dist/vue-composition-api.js"] = vueCapiEntry;
|
|
366
|
+
nuxt.options.alias["@vue/composition-api/dist/vue-composition-api.mjs"] = vueCapiEntry;
|
|
367
|
+
nuxt.options.alias["@vue/composition-api"] = vueCapiEntry;
|
|
359
368
|
const capiPluginPath = resolve(distDir, "runtime/capi.plugin.mjs");
|
|
360
369
|
addPluginTemplate({ filename: "capi.plugin.mjs", src: capiPluginPath });
|
|
361
370
|
const appPlugin = addPluginTemplate(resolve(distDir, "runtime/app.plugin.mjs"));
|
|
@@ -372,6 +381,106 @@ function setupCAPIBridge(_options) {
|
|
|
372
381
|
addWebpackPlugin(KeyPlugin.webpack());
|
|
373
382
|
}
|
|
374
383
|
|
|
384
|
+
function isObject(val) {
|
|
385
|
+
return val !== null && typeof val === "object";
|
|
386
|
+
}
|
|
387
|
+
function _defu(baseObj, defaults, namespace = ".", merger) {
|
|
388
|
+
if (!isObject(defaults)) {
|
|
389
|
+
return _defu(baseObj, {}, namespace, merger);
|
|
390
|
+
}
|
|
391
|
+
const obj = Object.assign({}, defaults);
|
|
392
|
+
for (const key in baseObj) {
|
|
393
|
+
if (key === "__proto__" || key === "constructor") {
|
|
394
|
+
continue;
|
|
395
|
+
}
|
|
396
|
+
const val = baseObj[key];
|
|
397
|
+
if (val === null || val === void 0) {
|
|
398
|
+
continue;
|
|
399
|
+
}
|
|
400
|
+
if (merger && merger(obj, key, val, namespace)) {
|
|
401
|
+
continue;
|
|
402
|
+
}
|
|
403
|
+
if (Array.isArray(val) && Array.isArray(obj[key])) {
|
|
404
|
+
obj[key] = obj[key].concat(val);
|
|
405
|
+
} else if (isObject(val) && isObject(obj[key])) {
|
|
406
|
+
obj[key] = _defu(val, obj[key], (namespace ? `${namespace}.` : "") + key.toString(), merger);
|
|
407
|
+
} else {
|
|
408
|
+
obj[key] = val;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
return obj;
|
|
412
|
+
}
|
|
413
|
+
function extend(merger) {
|
|
414
|
+
return (...args) => args.reduce((p, c) => _defu(p, c, "", merger), {});
|
|
415
|
+
}
|
|
416
|
+
const defu = extend();
|
|
417
|
+
defu.fn = extend((obj, key, currentValue, _namespace) => {
|
|
418
|
+
if (typeof obj[key] !== "undefined" && typeof currentValue === "function") {
|
|
419
|
+
obj[key] = currentValue(obj[key]);
|
|
420
|
+
return true;
|
|
421
|
+
}
|
|
422
|
+
});
|
|
423
|
+
defu.arrayFn = extend((obj, key, currentValue, _namespace) => {
|
|
424
|
+
if (Array.isArray(obj[key]) && typeof currentValue === "function") {
|
|
425
|
+
obj[key] = currentValue(obj[key]);
|
|
426
|
+
return true;
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
defu.extend = extend;
|
|
430
|
+
|
|
431
|
+
const DEFAULTS = {
|
|
432
|
+
fileSystem: new CachedInputFileSystem(fs, 4e3),
|
|
433
|
+
extensions: [".ts", ".mjs", ".cjs", ".js", ".json"],
|
|
434
|
+
mainFields: ["module", "main"]
|
|
435
|
+
};
|
|
436
|
+
const createResolver = (resolveOptions) => {
|
|
437
|
+
const options = defu(resolveOptions, DEFAULTS);
|
|
438
|
+
const resolver = ResolverFactory.createResolver(options);
|
|
439
|
+
const root = options.roots?.[0] || ".";
|
|
440
|
+
const promisifiedResolve = promisify(resolver.resolve.bind(resolver));
|
|
441
|
+
const resolve = (id, importer) => promisifiedResolve({}, importer || root, id, {});
|
|
442
|
+
return { resolve, resolver };
|
|
443
|
+
};
|
|
444
|
+
class EnhancedResolverPlugin {
|
|
445
|
+
constructor(options) {
|
|
446
|
+
this.resolver = createResolver(options);
|
|
447
|
+
}
|
|
448
|
+
apply(defaultResolver) {
|
|
449
|
+
const enhancedResolver = this.resolver;
|
|
450
|
+
defaultResolver.getHook("resolve").tapPromise("EnhancedResolverPlugin", async (request) => {
|
|
451
|
+
const id = request.request;
|
|
452
|
+
if (!id || !defaultResolver.isModule(id)) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
const importer = request.context?.issuer;
|
|
456
|
+
try {
|
|
457
|
+
const result = await enhancedResolver.resolve(id, importer);
|
|
458
|
+
if (!result) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
request.path = result;
|
|
462
|
+
return request;
|
|
463
|
+
} catch {
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
function setupBetterResolve() {
|
|
469
|
+
const nuxt = useNuxt();
|
|
470
|
+
extendWebpackConfig((config) => {
|
|
471
|
+
const isServer = config.name === "server";
|
|
472
|
+
config.resolve = config.resolve || {};
|
|
473
|
+
config.resolve.plugins = config.resolve.plugins || [];
|
|
474
|
+
config.resolve.plugins.push(new EnhancedResolverPlugin({
|
|
475
|
+
conditionNames: ["import", ...isServer ? ["node"] : []],
|
|
476
|
+
alias: config.resolve.alias,
|
|
477
|
+
modules: config.resolve.modules,
|
|
478
|
+
plugins: config.resolve.plugins,
|
|
479
|
+
roots: config.resolve.roots || [nuxt.options.rootDir]
|
|
480
|
+
}));
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
|
|
375
484
|
const module = defineNuxtModule({
|
|
376
485
|
name: "nuxt-bridge",
|
|
377
486
|
configKey: "bridge",
|
|
@@ -381,7 +490,8 @@ const module = defineNuxtModule({
|
|
|
381
490
|
app: {},
|
|
382
491
|
capi: {},
|
|
383
492
|
postcss8: true,
|
|
384
|
-
swc: true
|
|
493
|
+
swc: true,
|
|
494
|
+
resolve: true
|
|
385
495
|
},
|
|
386
496
|
async setup(opts, nuxt) {
|
|
387
497
|
if (opts.nitro) {
|
|
@@ -405,6 +515,9 @@ const module = defineNuxtModule({
|
|
|
405
515
|
if (opts.swc) {
|
|
406
516
|
await installModule(nuxt, require.resolve("nuxt-swc"));
|
|
407
517
|
}
|
|
518
|
+
if (opts.resolve) {
|
|
519
|
+
setupBetterResolve();
|
|
520
|
+
}
|
|
408
521
|
}
|
|
409
522
|
});
|
|
410
523
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxt/bridge-edge",
|
|
3
|
-
"version": "0.0.0-
|
|
3
|
+
"version": "0.0.0-27219596.a2da8a0",
|
|
4
4
|
"repository": "nuxt/framework",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "./dist/module.cjs",
|
|
@@ -12,16 +12,17 @@
|
|
|
12
12
|
"prepack": "unbuild"
|
|
13
13
|
},
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@nuxt/kit": "npm:@nuxt/kit-edge@0.10.0-
|
|
16
|
-
"@nuxt/nitro": "npm:@nuxt/nitro-edge@0.10.0-
|
|
15
|
+
"@nuxt/kit": "npm:@nuxt/kit-edge@0.10.0-27219596.a2da8a0",
|
|
16
|
+
"@nuxt/nitro": "npm:@nuxt/nitro-edge@0.10.0-27219596.a2da8a0",
|
|
17
17
|
"@nuxt/postcss8": "^1.1.3",
|
|
18
18
|
"@vue/composition-api": "^1.2.2",
|
|
19
19
|
"acorn": "^8.5.0",
|
|
20
|
-
"
|
|
20
|
+
"enhanced-resolve": "^5.8.3",
|
|
21
|
+
"estree-walker": "^2.0.2",
|
|
21
22
|
"fs-extra": "^10.0.0",
|
|
22
23
|
"magic-string": "^0.25.7",
|
|
23
24
|
"node-fetch": "^3.0.0",
|
|
24
|
-
"nuxi": "npm:nuxi-edge@0.10.0-
|
|
25
|
+
"nuxi": "npm:nuxi-edge@0.10.0-27219596.a2da8a0",
|
|
25
26
|
"nuxt-swc": "^0.1.0",
|
|
26
27
|
"nuxt-vite": "^0.2.4",
|
|
27
28
|
"pathe": "^0.2.0",
|