@edgeone/nuxt-pages 1.1.0-beta.3 → 1.1.0

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.
@@ -7,7 +7,7 @@
7
7
  import {
8
8
  require_out,
9
9
  verifyNuxtHandlerDirStructure
10
- } from "./chunk-NJ4SUJNF.js";
10
+ } from "./chunk-K5VT7O2H.js";
11
11
  import {
12
12
  __require,
13
13
  __toESM
@@ -101,10 +101,10 @@ var createServerHandler = async (ctx) => {
101
101
  };
102
102
  async function patchNitroHandler(ctx) {
103
103
  const fs = __require("fs");
104
- const defaultNitroMjsPath = ".edgeone/server-handler/chunks/nitro/nitro.mjs";
105
- const fallbackNitroMjsPath = ".edgeone/server-handler/chunks/_/nitro.mjs";
104
+ const defaultNitroMjsPath = join(ctx.serverHandlerDir, "chunks", "nitro", "nitro.mjs");
105
+ const fallbackNitroMjsPath = join(ctx.serverHandlerDir, "chunks", "_", "nitro.mjs");
106
106
  const nitroMjsPath = fs.existsSync(defaultNitroMjsPath) ? defaultNitroMjsPath : fallbackNitroMjsPath;
107
- const handlerTmplPath = ".edgeone/server-handler/handler.js";
107
+ const handlerTmplPath = join(ctx.serverHandlerRootDir, "handler.js");
108
108
  const nitroCode = fs.readFileSync(nitroMjsPath, "utf-8");
109
109
  const match = nitroCode.match(/export\s*\{[^}]*\buseNitroApp\s+as\s+([A-Za-z_$][\w$]*)/) ?? nitroCode.match(/\buseNitroApp\s+as\s+([A-Za-z_$][\w$]*)\b/);
110
110
  if (!match) throw new Error("Cannot find useNitroApp export symbol in nitro.mjs!");
@@ -5,8 +5,7 @@
5
5
  })();
6
6
 
7
7
  import {
8
- __commonJS,
9
- __toESM
8
+ __commonJS
10
9
  } from "./chunk-6BT4RYQJ.js";
11
10
 
12
11
  // node_modules/@babel/parser/lib/index.js
@@ -1557,12 +1556,12 @@ var require_lib = __commonJS({
1557
1556
  }
1558
1557
  };
1559
1558
  var ScopeHandler = class {
1560
- constructor(parser2, inModule) {
1559
+ constructor(parser, inModule) {
1561
1560
  this.parser = void 0;
1562
1561
  this.scopeStack = [];
1563
1562
  this.inModule = void 0;
1564
1563
  this.undefinedExports = /* @__PURE__ */ new Map();
1565
- this.parser = parser2;
1564
+ this.parser = parser;
1566
1565
  this.inModule = inModule;
1567
1566
  }
1568
1567
  get inTopLevel() {
@@ -3103,14 +3102,14 @@ var require_lib = __commonJS({
3103
3102
  super.checkParams(node, false, true);
3104
3103
  this.scope.exit();
3105
3104
  }
3106
- forwardNoArrowParamsConversionAt(node, parse3) {
3105
+ forwardNoArrowParamsConversionAt(node, parse2) {
3107
3106
  let result;
3108
3107
  if (this.state.noArrowParamsConversionAt.includes(this.offsetToSourcePos(node.start))) {
3109
3108
  this.state.noArrowParamsConversionAt.push(this.state.start);
3110
- result = parse3();
3109
+ result = parse2();
3111
3110
  this.state.noArrowParamsConversionAt.pop();
3112
3111
  } else {
3113
- result = parse3();
3112
+ result = parse2();
3114
3113
  }
3115
3114
  return result;
3116
3115
  }
@@ -6692,11 +6691,11 @@ var require_lib = __commonJS({
6692
6691
  }
6693
6692
  };
6694
6693
  var ClassScopeHandler = class {
6695
- constructor(parser2) {
6694
+ constructor(parser) {
6696
6695
  this.parser = void 0;
6697
6696
  this.stack = [];
6698
6697
  this.undefinedPrivateNames = /* @__PURE__ */ new Map();
6699
- this.parser = parser2;
6698
+ this.parser = parser;
6700
6699
  }
6701
6700
  current() {
6702
6701
  return this.stack[this.stack.length - 1];
@@ -6789,10 +6788,10 @@ var require_lib = __commonJS({
6789
6788
  }
6790
6789
  };
6791
6790
  var ExpressionScopeHandler = class {
6792
- constructor(parser2) {
6791
+ constructor(parser) {
6793
6792
  this.parser = void 0;
6794
6793
  this.stack = [new ExpressionScope()];
6795
- this.parser = parser2;
6794
+ this.parser = parser;
6796
6795
  }
6797
6796
  enter(scope) {
6798
6797
  this.stack.push(scope);
@@ -7105,13 +7104,13 @@ var require_lib = __commonJS({
7105
7104
  }
7106
7105
  };
7107
7106
  var Node = class {
7108
- constructor(parser2, pos, loc) {
7107
+ constructor(parser, pos, loc) {
7109
7108
  this.type = "";
7110
7109
  this.start = pos;
7111
7110
  this.end = 0;
7112
7111
  this.loc = new SourceLocation(loc);
7113
- if ((parser2 == null ? void 0 : parser2.optionFlags) & 128) this.range = [pos, 0];
7114
- if (parser2 != null && parser2.filename) this.loc.filename = parser2.filename;
7112
+ if ((parser == null ? void 0 : parser.optionFlags) & 128) this.range = [pos, 0];
7113
+ if (parser != null && parser.filename) this.loc.filename = parser.filename;
7115
7114
  }
7116
7115
  };
7117
7116
  var NodePrototype = Node.prototype;
@@ -14492,18 +14491,18 @@ var require_lib = __commonJS({
14492
14491
  return file;
14493
14492
  }
14494
14493
  };
14495
- function parse2(input, options) {
14494
+ function parse(input, options) {
14496
14495
  var _options;
14497
14496
  if (((_options = options) == null ? void 0 : _options.sourceType) === "unambiguous") {
14498
14497
  options = Object.assign({}, options);
14499
14498
  try {
14500
14499
  options.sourceType = "module";
14501
- const parser2 = getParser(options, input);
14502
- const ast = parser2.parse();
14503
- if (parser2.sawUnambiguousESM) {
14500
+ const parser = getParser(options, input);
14501
+ const ast = parser.parse();
14502
+ if (parser.sawUnambiguousESM) {
14504
14503
  return ast;
14505
14504
  }
14506
- if (parser2.ambiguousScriptDifferentAst) {
14505
+ if (parser.ambiguousScriptDifferentAst) {
14507
14506
  try {
14508
14507
  options.sourceType = "script";
14509
14508
  return getParser(options, input).parse();
@@ -14526,11 +14525,11 @@ var require_lib = __commonJS({
14526
14525
  }
14527
14526
  }
14528
14527
  function parseExpression(input, options) {
14529
- const parser2 = getParser(options, input);
14530
- if (parser2.options.strictMode) {
14531
- parser2.state.strict = true;
14528
+ const parser = getParser(options, input);
14529
+ if (parser.options.strictMode) {
14530
+ parser.state.strict = true;
14532
14531
  }
14533
- return parser2.getExpression();
14532
+ return parser.getExpression();
14534
14533
  }
14535
14534
  function generateExportedTokenTypes(internalTokenTypes) {
14536
14535
  const tokenTypes2 = {};
@@ -14579,528 +14578,12 @@ var require_lib = __commonJS({
14579
14578
  }
14580
14579
  return cls;
14581
14580
  }
14582
- exports.parse = parse2;
14581
+ exports.parse = parse;
14583
14582
  exports.parseExpression = parseExpression;
14584
14583
  exports.tokTypes = tokTypes;
14585
14584
  }
14586
14585
  });
14587
14586
 
14588
- // src/utils.ts
14589
- var parser = __toESM(require_lib(), 1);
14590
- import { createRequire } from "node:module";
14591
- import * as fs from "fs";
14592
- import * as path from "path";
14593
- var require2 = createRequire(import.meta.url);
14594
- var traverse = require2("@babel/traverse").default;
14595
- function useStaticBuild(cwd) {
14596
- const edgeoneJsonPath = path.join(cwd, "edgeone.json");
14597
- let originalEdgeOneConfig = null;
14598
- let config = {};
14599
- if (!fs.existsSync(edgeoneJsonPath)) {
14600
- fs.writeFileSync(edgeoneJsonPath, "{}", "utf-8");
14601
- config = {};
14602
- } else {
14603
- try {
14604
- const fileContent = fs.readFileSync(edgeoneJsonPath, "utf-8");
14605
- originalEdgeOneConfig = fileContent;
14606
- config = JSON.parse(fileContent);
14607
- } catch (error) {
14608
- console.error("\u8BFB\u53D6 edgeone.json \u6587\u4EF6\u5931\u8D25:", error);
14609
- config = {};
14610
- }
14611
- }
14612
- config.buildCommand = "npm run generate";
14613
- try {
14614
- fs.writeFileSync(edgeoneJsonPath, JSON.stringify(config, null, 2), "utf-8");
14615
- } catch (error) {
14616
- console.error("\u5199\u5165 edgeone.json \u6587\u4EF6\u5931\u8D25:", error);
14617
- throw error;
14618
- }
14619
- return originalEdgeOneConfig;
14620
- }
14621
- function resetEdgeOneConfig(cwd, originalEdgeOneConfig) {
14622
- const edgeoneJsonPath = path.join(cwd, "edgeone.json");
14623
- try {
14624
- if (originalEdgeOneConfig == null) {
14625
- fs.rmSync(edgeoneJsonPath, { recursive: true, force: true });
14626
- return;
14627
- }
14628
- fs.writeFileSync(edgeoneJsonPath, originalEdgeOneConfig, "utf-8");
14629
- } catch (error) {
14630
- console.error("\u5199\u5165 edgeone.json \u6587\u4EF6\u5931\u8D25:", error);
14631
- throw error;
14632
- }
14633
- }
14634
- function astNodeToObject(node) {
14635
- if (node.type === "ObjectExpression") {
14636
- const obj = {};
14637
- for (const prop of node.properties) {
14638
- if (prop.type === "ObjectProperty" && prop.key.type === "Identifier") {
14639
- obj[prop.key.name] = astNodeToObject(prop.value);
14640
- } else if (prop.type === "ObjectProperty" && prop.key.type === "StringLiteral") {
14641
- obj[prop.key.value] = astNodeToObject(prop.value);
14642
- }
14643
- }
14644
- return obj;
14645
- } else if (node.type === "ArrayExpression") {
14646
- return node.elements.map((element) => element ? astNodeToObject(element) : null);
14647
- } else if (node.type === "StringLiteral" || node.type === "NumericLiteral" || node.type === "BooleanLiteral") {
14648
- return node.value;
14649
- } else if (node.type === "NullLiteral") {
14650
- return null;
14651
- } else {
14652
- console.warn(`Unsupported node type in astNodeToObject: ${node.type}`);
14653
- return void 0;
14654
- }
14655
- }
14656
- function getRouteRulesWithAST(code) {
14657
- try {
14658
- const ast = parser.parse(code, {
14659
- sourceType: "module",
14660
- plugins: ["typescript"]
14661
- });
14662
- let routeRulesObject = null;
14663
- traverse(ast, {
14664
- // We're looking for a function call
14665
- CallExpression(path2) {
14666
- const { node } = path2;
14667
- if (node.callee.type === "Identifier" && node.callee.name === "defineNuxtConfig") {
14668
- if (node.arguments.length > 0 && node.arguments[0].type === "ObjectExpression") {
14669
- const configObjectNode = node.arguments[0];
14670
- for (const prop of configObjectNode.properties) {
14671
- if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "routeRules") {
14672
- routeRulesObject = astNodeToObject(prop.value);
14673
- path2.stop();
14674
- break;
14675
- }
14676
- }
14677
- }
14678
- }
14679
- }
14680
- });
14681
- return routeRulesObject;
14682
- } catch (e) {
14683
- console.error("AST parsing or traversal failed:", e);
14684
- return null;
14685
- }
14686
- }
14687
- function getPrerenderRoutesWithAST(code) {
14688
- try {
14689
- const ast = parser.parse(code, {
14690
- sourceType: "module",
14691
- plugins: ["typescript"]
14692
- });
14693
- let prerenderRoutes = [];
14694
- traverse(ast, {
14695
- // We're looking for a function call
14696
- CallExpression(path2) {
14697
- const { node } = path2;
14698
- if (node.callee.type === "Identifier" && node.callee.name === "defineNuxtConfig") {
14699
- if (node.arguments.length > 0 && node.arguments[0].type === "ObjectExpression") {
14700
- const configObjectNode = node.arguments[0];
14701
- for (const prop of configObjectNode.properties) {
14702
- if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "nitro" && prop.value.type === "ObjectExpression") {
14703
- for (const nitroProp of prop.value.properties) {
14704
- if (nitroProp.type === "ObjectProperty" && nitroProp.key.type === "Identifier" && nitroProp.key.name === "prerender" && nitroProp.value.type === "ObjectExpression") {
14705
- for (const prerenderProp of nitroProp.value.properties) {
14706
- if (prerenderProp.type === "ObjectProperty" && prerenderProp.key.type === "Identifier" && prerenderProp.key.name === "routes" && prerenderProp.value.type === "ArrayExpression") {
14707
- const routesArray = astNodeToObject(prerenderProp.value);
14708
- if (Array.isArray(routesArray)) {
14709
- prerenderRoutes = routesArray.filter((route) => typeof route === "string");
14710
- }
14711
- path2.stop();
14712
- return;
14713
- }
14714
- }
14715
- }
14716
- }
14717
- }
14718
- }
14719
- }
14720
- }
14721
- }
14722
- });
14723
- return prerenderRoutes;
14724
- } catch (e) {
14725
- console.error("AST parsing or traversal failed:", e);
14726
- return [];
14727
- }
14728
- }
14729
- function getRoutesArrayWithAST(code) {
14730
- try {
14731
- const ast = parser.parse(code, {
14732
- sourceType: "module",
14733
- plugins: ["typescript"]
14734
- });
14735
- let routesArray = null;
14736
- traverse(ast, {
14737
- // We're looking for a variable declaration
14738
- VariableDeclaration(path2) {
14739
- const { node } = path2;
14740
- for (const declarator of node.declarations) {
14741
- if (declarator.type === "VariableDeclarator" && declarator.id.type === "Identifier" && declarator.id.name === "_routes") {
14742
- if (declarator.init && declarator.init.type === "ArrayExpression") {
14743
- routesArray = astNodeToObjectForRoutes(declarator.init);
14744
- path2.stop();
14745
- break;
14746
- }
14747
- }
14748
- }
14749
- }
14750
- });
14751
- return routesArray;
14752
- } catch (e) {
14753
- console.error("AST parsing or traversal failed:", e);
14754
- return null;
14755
- }
14756
- }
14757
- function getHandlersArrayWithAST(code) {
14758
- try {
14759
- const ast = parser.parse(code, {
14760
- sourceType: "module",
14761
- plugins: ["typescript"]
14762
- });
14763
- let handlersArray = [];
14764
- traverse(ast, {
14765
- // We're looking for a variable declaration
14766
- VariableDeclaration(path2) {
14767
- const { node } = path2;
14768
- for (const declarator of node.declarations) {
14769
- if (declarator.type === "VariableDeclarator" && declarator.id.type === "Identifier" && declarator.id.name === "handlers") {
14770
- if (declarator.init && declarator.init.type === "ArrayExpression") {
14771
- handlersArray = astNodeToObjectForRoutes(declarator.init);
14772
- path2.stop();
14773
- break;
14774
- }
14775
- }
14776
- }
14777
- }
14778
- });
14779
- return handlersArray;
14780
- } catch (e) {
14781
- console.error("AST parsing or traversal failed:", e);
14782
- return [];
14783
- }
14784
- }
14785
- function addCodeToGenerateEdgeoneWithAST(code, insertCode) {
14786
- try {
14787
- const ast = parser.parse(code, {
14788
- sourceType: "module",
14789
- plugins: ["typescript"]
14790
- });
14791
- let oldOutputValue = null;
14792
- let configObjectNode = null;
14793
- let configStart = null;
14794
- let configEnd = null;
14795
- let nitroProperty = null;
14796
- let hasNitro = false;
14797
- let presetValue = null;
14798
- traverse(ast, {
14799
- CallExpression(path2) {
14800
- const { node } = path2;
14801
- if (node.callee.type === "Identifier" && node.callee.name === "defineNuxtConfig") {
14802
- if (node.arguments.length > 0 && node.arguments[0].type === "ObjectExpression") {
14803
- configObjectNode = node.arguments[0];
14804
- configStart = configObjectNode.start;
14805
- configEnd = configObjectNode.end;
14806
- for (const prop of configObjectNode.properties) {
14807
- if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "nitro") {
14808
- hasNitro = true;
14809
- nitroProperty = prop;
14810
- break;
14811
- }
14812
- }
14813
- path2.stop();
14814
- }
14815
- }
14816
- }
14817
- });
14818
- if (!configObjectNode || configStart === null || configEnd === null) {
14819
- return null;
14820
- }
14821
- let newConfigCode = "";
14822
- let needsUpdate = true;
14823
- const newOutputConfig = {
14824
- dir: ".edgeone",
14825
- publicDir: ".edgeone/assets",
14826
- serverDir: ".edgeone/server-handler"
14827
- };
14828
- if (!hasNitro) {
14829
- oldOutputValue = null;
14830
- const existingConfigContent = code.slice(configStart + 1, configEnd - 1).trim();
14831
- const nitroConfig = ` nitro: {
14832
- output: {
14833
- dir: '.edgeone',
14834
- publicDir: '.edgeone/assets',
14835
- serverDir: '.edgeone/server-handler',
14836
- },
14837
- }`;
14838
- if (existingConfigContent) {
14839
- const trimmedContent = existingConfigContent.replace(/,\s*$/, "");
14840
- newConfigCode = `{
14841
- ${trimmedContent},
14842
- ${nitroConfig}
14843
- }`;
14844
- } else {
14845
- newConfigCode = `{
14846
- ${nitroConfig}
14847
- }`;
14848
- }
14849
- } else {
14850
- const nitroStart = nitroProperty.value.start;
14851
- const nitroEnd = nitroProperty.value.end;
14852
- let hasOutput = false;
14853
- let hasPreset = false;
14854
- if (nitroProperty.value.type === "ObjectExpression") {
14855
- for (const nitroProp of nitroProperty.value.properties) {
14856
- if (nitroProp.type === "ObjectProperty" && nitroProp.key.type === "Identifier") {
14857
- if (nitroProp.key.name === "output") {
14858
- hasOutput = true;
14859
- oldOutputValue = astNodeToObject(nitroProp.value);
14860
- } else if (nitroProp.key.name === "preset") {
14861
- hasPreset = true;
14862
- presetValue = astNodeToObject(nitroProp.value);
14863
- }
14864
- }
14865
- }
14866
- }
14867
- if (!hasOutput) {
14868
- oldOutputValue = null;
14869
- }
14870
- const needsPresetUpdate = hasPreset && presetValue !== "node-server";
14871
- const outputConfigStr = ` output: {
14872
- dir: '.edgeone',
14873
- publicDir: '.edgeone/assets',
14874
- serverDir: '.edgeone/server-handler',
14875
- }`;
14876
- let newNitroContent;
14877
- const properties = [];
14878
- for (const nitroProp of nitroProperty.value.properties) {
14879
- if (nitroProp.type === "ObjectProperty" && nitroProp.key.type === "Identifier") {
14880
- if (nitroProp.key.name === "output") {
14881
- properties.push(outputConfigStr);
14882
- } else if (nitroProp.key.name === "preset") {
14883
- continue;
14884
- } else {
14885
- const propStart = nitroProp.start - nitroStart;
14886
- const propEnd = nitroProp.end - nitroStart;
14887
- const propContent = code.slice(nitroStart + propStart, nitroStart + propEnd);
14888
- properties.push(` ${propContent.trim()}`);
14889
- }
14890
- }
14891
- }
14892
- if (!hasOutput) {
14893
- properties.push(outputConfigStr);
14894
- }
14895
- newNitroContent = `{
14896
- ${properties.join(",\n")}
14897
- }`;
14898
- const beforeNitro = code.slice(configStart, nitroStart);
14899
- const afterNitro = code.slice(nitroEnd, configEnd);
14900
- newConfigCode = beforeNitro + newNitroContent + afterNitro;
14901
- }
14902
- const newCode = code.slice(0, configStart) + newConfigCode + code.slice(configEnd);
14903
- try {
14904
- parser.parse(newCode, {
14905
- sourceType: "module",
14906
- plugins: ["typescript"]
14907
- });
14908
- } catch (parseError) {
14909
- console.warn("Generated code has syntax issues:", parseError);
14910
- }
14911
- return {
14912
- oldPreset: presetValue,
14913
- oldOutput: oldOutputValue,
14914
- newCode
14915
- };
14916
- } catch (e) {
14917
- console.error("AST parsing or traversal failed:", e);
14918
- return null;
14919
- }
14920
- }
14921
- function astNodeToObjectForRoutes(node) {
14922
- if (node.type === "ObjectExpression") {
14923
- const obj = {};
14924
- for (const prop of node.properties) {
14925
- if (prop.type === "ObjectProperty") {
14926
- let key;
14927
- if (prop.key.type === "Identifier") {
14928
- key = prop.key.name;
14929
- } else if (prop.key.type === "StringLiteral") {
14930
- key = prop.key.value;
14931
- } else {
14932
- continue;
14933
- }
14934
- if (prop.value.type === "ArrowFunctionExpression") {
14935
- if (prop.value.body.type === "CallExpression" && prop.value.body.callee.type === "Import" && prop.value.body.arguments.length > 0 && prop.value.body.arguments[0].type === "StringLiteral") {
14936
- const importPath = prop.value.body.arguments[0].value;
14937
- obj[key] = `() => import('${importPath}')`;
14938
- } else {
14939
- obj[key] = "[Function]";
14940
- }
14941
- } else {
14942
- obj[key] = astNodeToObjectForRoutes(prop.value);
14943
- }
14944
- }
14945
- }
14946
- return obj;
14947
- } else if (node.type === "ArrayExpression") {
14948
- return node.elements.map((element) => element ? astNodeToObjectForRoutes(element) : null);
14949
- } else if (node.type === "StringLiteral" || node.type === "NumericLiteral" || node.type === "BooleanLiteral") {
14950
- return node.value;
14951
- } else if (node.type === "NullLiteral") {
14952
- return null;
14953
- } else {
14954
- return `[${node.type}]`;
14955
- }
14956
- }
14957
- function resetNitroConfigWithAST(code, oldOutput, oldPreset) {
14958
- try {
14959
- const ast = parser.parse(code, {
14960
- sourceType: "module",
14961
- plugins: ["typescript"]
14962
- });
14963
- let configObjectNode = null;
14964
- let configStart = null;
14965
- let configEnd = null;
14966
- let nitroProperty = null;
14967
- let hasNitro = false;
14968
- traverse(ast, {
14969
- CallExpression(path2) {
14970
- const { node } = path2;
14971
- if (node.callee.type === "Identifier" && node.callee.name === "defineNuxtConfig") {
14972
- if (node.arguments.length > 0 && node.arguments[0].type === "ObjectExpression") {
14973
- configObjectNode = node.arguments[0];
14974
- configStart = configObjectNode.start;
14975
- configEnd = configObjectNode.end;
14976
- for (const prop of configObjectNode.properties) {
14977
- if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "nitro") {
14978
- hasNitro = true;
14979
- nitroProperty = prop;
14980
- break;
14981
- }
14982
- }
14983
- path2.stop();
14984
- }
14985
- }
14986
- }
14987
- });
14988
- if (!configObjectNode || configStart === null || configEnd === null) {
14989
- return null;
14990
- }
14991
- if (!hasNitro) {
14992
- return code;
14993
- }
14994
- const nitroStart = nitroProperty.value.start;
14995
- const nitroEnd = nitroProperty.value.end;
14996
- const properties = [];
14997
- for (const nitroProp of nitroProperty.value.properties) {
14998
- if (nitroProp.type === "ObjectProperty" && nitroProp.key.type === "Identifier") {
14999
- const propName = nitroProp.key.name;
15000
- if (propName === "output") {
15001
- if (oldOutput !== null && oldOutput !== void 0) {
15002
- let outputConfigStr = "";
15003
- if (typeof oldOutput === "object" && oldOutput !== null) {
15004
- const outputProps = [];
15005
- for (const [key, value] of Object.entries(oldOutput)) {
15006
- if (typeof value === "string") {
15007
- outputProps.push(` ${key}: '${value}'`);
15008
- } else if (typeof value === "number" || typeof value === "boolean") {
15009
- outputProps.push(` ${key}: ${value}`);
15010
- } else {
15011
- outputProps.push(` ${key}: ${JSON.stringify(value)}`);
15012
- }
15013
- }
15014
- outputConfigStr = ` output: {
15015
- ${outputProps.join(",\n")}
15016
- }`;
15017
- } else {
15018
- outputConfigStr = ` output: ${JSON.stringify(oldOutput)}`;
15019
- }
15020
- properties.push(outputConfigStr);
15021
- }
15022
- } else if (propName === "preset") {
15023
- if (oldPreset !== null && oldPreset !== void 0) {
15024
- properties.push(` preset: '${oldPreset}'`);
15025
- }
15026
- } else {
15027
- const propStart = nitroProp.start - nitroStart;
15028
- const propEnd = nitroProp.end - nitroStart;
15029
- const propContent = code.slice(nitroStart + propStart, nitroStart + propEnd);
15030
- properties.push(` ${propContent.trim()}`);
15031
- }
15032
- }
15033
- }
15034
- let newNitroContent;
15035
- if (properties.length > 0) {
15036
- newNitroContent = `{
15037
- ${properties.join(",\n")}
15038
- }`;
15039
- } else {
15040
- newNitroContent = `{}`;
15041
- }
15042
- const beforeNitro = code.slice(configStart, nitroStart);
15043
- const afterNitro = code.slice(nitroEnd, configEnd);
15044
- const newConfigCode = beforeNitro + newNitroContent + afterNitro;
15045
- const newCode = code.slice(0, configStart) + newConfigCode + code.slice(configEnd);
15046
- return newCode;
15047
- } catch (e) {
15048
- console.error("AST parsing or traversal failed:", e);
15049
- return null;
15050
- }
15051
- }
15052
- function getModulesWithAST(code) {
15053
- try {
15054
- const ast = parser.parse(code, {
15055
- sourceType: "module",
15056
- plugins: ["typescript"]
15057
- });
15058
- let modulesArray = [];
15059
- traverse(ast, {
15060
- CallExpression(path2) {
15061
- const { node } = path2;
15062
- if (node.callee.type === "Identifier" && node.callee.name === "defineNuxtConfig") {
15063
- if (node.arguments.length > 0 && node.arguments[0].type === "ObjectExpression") {
15064
- const configObject = node.arguments[0];
15065
- for (const prop of configObject.properties) {
15066
- if (prop.type === "ObjectProperty" && prop.key.type === "Identifier" && prop.key.name === "modules") {
15067
- if (prop.value.type === "ArrayExpression") {
15068
- for (const element of prop.value.elements) {
15069
- if (element) {
15070
- if (element.type === "StringLiteral") {
15071
- modulesArray.push(element.value);
15072
- } else if (element.type === "ArrayExpression" && element.elements.length > 0) {
15073
- const firstElement = element.elements[0];
15074
- if (firstElement && firstElement.type === "StringLiteral") {
15075
- modulesArray.push(firstElement.value);
15076
- }
15077
- }
15078
- }
15079
- }
15080
- }
15081
- path2.stop();
15082
- return;
15083
- }
15084
- }
15085
- }
15086
- }
15087
- }
15088
- });
15089
- return modulesArray;
15090
- } catch (e) {
15091
- console.error("AST parsing or traversal failed:", e);
15092
- return [];
15093
- }
15094
- }
15095
-
15096
14587
  export {
15097
- useStaticBuild,
15098
- resetEdgeOneConfig,
15099
- getRouteRulesWithAST,
15100
- getPrerenderRoutesWithAST,
15101
- getRoutesArrayWithAST,
15102
- getHandlersArrayWithAST,
15103
- addCodeToGenerateEdgeoneWithAST,
15104
- resetNitroConfigWithAST,
15105
- getModulesWithAST
14588
+ require_lib
15106
14589
  };