unplugin-env 1.0.0 → 1.0.1

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/nuxt.cjs CHANGED
@@ -4309,41 +4309,41 @@ var require_queue = __commonJS({
4309
4309
  queue.drained = drained;
4310
4310
  return queue;
4311
4311
  function push(value) {
4312
- var p = new Promise(function(resolve2, reject) {
4312
+ var p = new Promise(function(resolve, reject) {
4313
4313
  pushCb(value, function(err, result) {
4314
4314
  if (err) {
4315
4315
  reject(err);
4316
4316
  return;
4317
4317
  }
4318
- resolve2(result);
4318
+ resolve(result);
4319
4319
  });
4320
4320
  });
4321
4321
  p.catch(noop);
4322
4322
  return p;
4323
4323
  }
4324
4324
  function unshift(value) {
4325
- var p = new Promise(function(resolve2, reject) {
4325
+ var p = new Promise(function(resolve, reject) {
4326
4326
  unshiftCb(value, function(err, result) {
4327
4327
  if (err) {
4328
4328
  reject(err);
4329
4329
  return;
4330
4330
  }
4331
- resolve2(result);
4331
+ resolve(result);
4332
4332
  });
4333
4333
  });
4334
4334
  p.catch(noop);
4335
4335
  return p;
4336
4336
  }
4337
4337
  function drained() {
4338
- var p = new Promise(function(resolve2) {
4338
+ var p = new Promise(function(resolve) {
4339
4339
  process.nextTick(function() {
4340
4340
  if (queue.idle()) {
4341
- resolve2();
4341
+ resolve();
4342
4342
  } else {
4343
4343
  var previousDrain = queue.drain;
4344
4344
  queue.drain = function() {
4345
4345
  if (typeof previousDrain === "function") previousDrain();
4346
- resolve2();
4346
+ resolve();
4347
4347
  queue.drain = previousDrain;
4348
4348
  };
4349
4349
  }
@@ -4829,9 +4829,9 @@ var require_stream3 = __commonJS({
4829
4829
  });
4830
4830
  }
4831
4831
  _getStat(filepath) {
4832
- return new Promise((resolve2, reject) => {
4832
+ return new Promise((resolve, reject) => {
4833
4833
  this._stat(filepath, this._fsStatSettings, (error, stats) => {
4834
- return error === null ? resolve2(stats) : reject(error);
4834
+ return error === null ? resolve(stats) : reject(error);
4835
4835
  });
4836
4836
  });
4837
4837
  }
@@ -4855,10 +4855,10 @@ var require_async5 = __commonJS({
4855
4855
  this._readerStream = new stream_1.default(this._settings);
4856
4856
  }
4857
4857
  dynamic(root, options) {
4858
- return new Promise((resolve2, reject) => {
4858
+ return new Promise((resolve, reject) => {
4859
4859
  this._walkAsync(root, options, (error, entries) => {
4860
4860
  if (error === null) {
4861
- resolve2(entries);
4861
+ resolve(entries);
4862
4862
  } else {
4863
4863
  reject(error);
4864
4864
  }
@@ -4868,10 +4868,10 @@ var require_async5 = __commonJS({
4868
4868
  async static(patterns, options) {
4869
4869
  const entries = [];
4870
4870
  const stream = this._readerStream.static(patterns, options);
4871
- return new Promise((resolve2, reject) => {
4871
+ return new Promise((resolve, reject) => {
4872
4872
  stream.once("error", reject);
4873
4873
  stream.on("data", (entry) => entries.push(entry));
4874
- stream.once("end", () => resolve2(entries));
4874
+ stream.once("end", () => resolve(entries));
4875
4875
  });
4876
4876
  }
4877
4877
  };
@@ -5544,127 +5544,10 @@ var import_node_fs3 = require("fs");
5544
5544
  var import_node_process4 = __toESM(require("process"), 1);
5545
5545
  var import_unplugin = require("unplugin");
5546
5546
 
5547
- // src/core/generate.ts
5548
- var import_node_path = __toESM(require("path"), 1);
5549
- var import_node_fs = require("fs");
5550
- var import_node_process = __toESM(require("process"), 1);
5551
- var import_fast_glob = __toESM(require_out4(), 1);
5552
- var import_recast = __toESM(require("recast"), 1);
5553
- function mergeObjects(prodObj, devObj) {
5554
- const prodProps = new Map(prodObj.properties.map((p) => [p.key.name || p.key.value, p]));
5555
- for (const prop of devObj.properties) {
5556
- const key = prop.key.name || prop.key.value;
5557
- if (prodProps.has(key)) {
5558
- const index = prodObj.properties.indexOf(prodProps.get(key));
5559
- if (index >= 0)
5560
- prodObj.properties[index] = prop;
5561
- } else {
5562
- prodObj.properties.push(prop);
5563
- }
5564
- }
5565
- }
5566
- async function generateScript(options, mode, base2) {
5567
- const { dir, fileName, globalName, serve, build } = options.env;
5568
- const folder = await findFolder(import_node_process.default.cwd(), dir);
5569
- const files = await (0, import_fast_glob.default)("*.+(js|ts)", {
5570
- absolute: true,
5571
- cwd: folder
5572
- });
5573
- const testReg = mode === "serve" ? serve : build;
5574
- let target = "";
5575
- let source = "";
5576
- let code = "";
5577
- const name = fileName;
5578
- for (const file of files) {
5579
- try {
5580
- const mod = await import_node_fs.promises.readFile(file, "utf-8");
5581
- if (testReg == null ? void 0 : testReg.test(file))
5582
- target = mod;
5583
- else
5584
- source = mod;
5585
- } catch (error) {
5586
- console.error(`Error loading file ${file}:`, error);
5587
- }
5588
- }
5589
- const targetAst = import_recast.default.parse(target);
5590
- const sourceAst = import_recast.default.parse(source);
5591
- const targetExport = targetAst.program.body.find((n) => n.type === "ExportDefaultDeclaration").declaration;
5592
- const sourceExport = sourceAst.program.body.find((n) => n.type === "ExportDefaultDeclaration").declaration;
5593
- mergeObjects(sourceExport, targetExport);
5594
- const mergedCode = import_recast.default.print(sourceExport).code;
5595
- const returnedTarget = mergedCode;
5596
- const versionInfo = await generateVersion(options, mode);
5597
- code = `window.${globalName}=${returnedTarget};${versionInfo}`;
5598
- const formatCode = code;
5599
- return {
5600
- code,
5601
- script: ` <script type="text/javascript" src="${base2}${fileName}"></script>
5602
- </head>`,
5603
- emit: {
5604
- type: "asset",
5605
- fileName: name,
5606
- source: formatCode
5607
- },
5608
- watchFiles: files
5609
- };
5610
- }
5611
- async function generateVersion(options, mode) {
5612
- const packageFile = await (0, import_fast_glob.default)("package.json", {
5613
- absolute: true,
5614
- cwd: (0, import_node_path.resolve)(import_node_process.default.cwd())
5615
- });
5616
- const packageString = await import_node_fs.promises.readFile(packageFile[0], "utf8");
5617
- const packageJson = JSON.parse(packageString);
5618
- return `console.info("Version: ${packageJson.version} - ${mode === "serve" ? "runtime" : "built"} on ${options.date}")`;
5619
- }
5620
- async function findFolder(directoryPath, dir) {
5621
- const ignore = /* @__PURE__ */ new Set(["dist", "node_modules", "playground", "example", "test", "jest", "tests", "locales", "public", ".git", ".github", ".vscode"]);
5622
- const files = await import_node_fs.promises.readdir(directoryPath);
5623
- const filePaths = files.filter((item) => !ignore.has(item));
5624
- let nestedFolder = "";
5625
- for (const file of filePaths) {
5626
- const fullFilePath = import_node_path.default.join(directoryPath, file);
5627
- const stat = await import_node_fs.promises.stat(fullFilePath);
5628
- if (stat.isDirectory()) {
5629
- if (file.toLowerCase() === dir) {
5630
- return fullFilePath;
5631
- } else {
5632
- nestedFolder = await findFolder(fullFilePath, dir);
5633
- if (nestedFolder)
5634
- return nestedFolder;
5635
- }
5636
- }
5637
- }
5638
- return "";
5639
- }
5640
-
5641
- // src/core/options.ts
5642
- var import_utils = require("@antfu/utils");
5643
- function resolveOptions(options) {
5644
- const defaults = {
5645
- env: {
5646
- dir: "config",
5647
- fileName: "manifest.js",
5648
- globalName: "manifest",
5649
- serve: /dev|development/i,
5650
- build: /prod|production/i
5651
- },
5652
- compress: {
5653
- outDir: "dist",
5654
- ignoreBase: true
5655
- }
5656
- };
5657
- const mergeOptions = (0, import_utils.deepMerge)(defaults, options);
5658
- return {
5659
- ...mergeOptions,
5660
- date: (/* @__PURE__ */ new Date()).toLocaleString()
5661
- };
5662
- }
5663
-
5664
5547
  // src/core/compress.ts
5665
- var import_node_fs2 = __toESM(require("fs"), 1);
5666
- var import_node_path2 = __toESM(require("path"), 1);
5667
- var import_node_process3 = __toESM(require("process"), 1);
5548
+ var import_node_fs = __toESM(require("fs"), 1);
5549
+ var import_node_path = __toESM(require("path"), 1);
5550
+ var import_node_process2 = __toESM(require("process"), 1);
5668
5551
  var import_archiver = __toESM(require("archiver"), 1);
5669
5552
 
5670
5553
  // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
@@ -5854,16 +5737,16 @@ var ansiStyles = assembleStyles();
5854
5737
  var ansi_styles_default = ansiStyles;
5855
5738
 
5856
5739
  // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.js
5857
- var import_node_process2 = __toESM(require("process"), 1);
5740
+ var import_node_process = __toESM(require("process"), 1);
5858
5741
  var import_node_os = __toESM(require("os"), 1);
5859
5742
  var import_node_tty = __toESM(require("tty"), 1);
5860
- function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process2.default.argv) {
5743
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) {
5861
5744
  const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
5862
5745
  const position = argv.indexOf(prefix + flag);
5863
5746
  const terminatorPosition = argv.indexOf("--");
5864
5747
  return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
5865
5748
  }
5866
- var { env } = import_node_process2.default;
5749
+ var { env } = import_node_process.default;
5867
5750
  var flagForceColor;
5868
5751
  if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
5869
5752
  flagForceColor = 0;
@@ -5919,7 +5802,7 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
5919
5802
  if (env.TERM === "dumb") {
5920
5803
  return min;
5921
5804
  }
5922
- if (import_node_process2.default.platform === "win32") {
5805
+ if (import_node_process.default.platform === "win32") {
5923
5806
  const osRelease = import_node_os.default.release().split(".");
5924
5807
  if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
5925
5808
  return Number(osRelease[2]) >= 14931 ? 3 : 2;
@@ -6179,15 +6062,15 @@ var Log = class {
6179
6062
  // src/core/compress.ts
6180
6063
  async function createCompress(options) {
6181
6064
  const { outDir, ignoreBase } = options;
6182
- const zipFilePath = import_node_path2.default.resolve(import_node_process3.default.cwd(), `${import_node_path2.default.basename(outDir)}.zip`);
6065
+ const zipFilePath = import_node_path.default.resolve(import_node_process2.default.cwd(), `${import_node_path.default.basename(outDir)}.zip`);
6183
6066
  Log.log("Compressing the directory", outDir);
6184
- return new Promise((resolve2, reject) => {
6067
+ return new Promise((resolve, reject) => {
6185
6068
  try {
6186
- const output = import_node_fs2.default.createWriteStream(zipFilePath);
6069
+ const output = import_node_fs.default.createWriteStream(zipFilePath);
6187
6070
  const archive = (0, import_archiver.default)("zip");
6188
6071
  output.on("close", () => {
6189
- Log.success("Successfully compressed to", `${zipFilePath} (${archive.pointer() / 1024 / 1024} MB)`);
6190
- resolve2(null);
6072
+ Log.success("Successfully compressed to", `${zipFilePath} (${(archive.pointer() / 1024 / 1024).toFixed(1)} MB)`);
6073
+ resolve(null);
6191
6074
  });
6192
6075
  archive.on("warning", (err) => {
6193
6076
  if (err.code === "ENOENT")
@@ -6200,8 +6083,8 @@ async function createCompress(options) {
6200
6083
  reject(err);
6201
6084
  });
6202
6085
  archive.pipe(output);
6203
- const absoluteOutDir = import_node_path2.default.resolve(outDir);
6204
- archive.directory(absoluteOutDir, ignoreBase ? false : import_node_path2.default.basename(outDir));
6086
+ const absoluteOutDir = import_node_path.default.resolve(outDir);
6087
+ archive.directory(absoluteOutDir, ignoreBase ? false : import_node_path.default.basename(outDir));
6205
6088
  archive.finalize();
6206
6089
  } catch (error) {
6207
6090
  Log.error("Error compressing the directory", error);
@@ -6210,6 +6093,124 @@ async function createCompress(options) {
6210
6093
  });
6211
6094
  }
6212
6095
 
6096
+ // src/core/generate.ts
6097
+ var import_node_fs2 = require("fs");
6098
+ var import_node_path2 = __toESM(require("path"), 1);
6099
+ var import_node_process3 = __toESM(require("process"), 1);
6100
+ var import_fast_glob = __toESM(require_out4(), 1);
6101
+ var import_local_pkg = require("local-pkg");
6102
+ var import_recast = __toESM(require("recast"), 1);
6103
+ function mergeObjects(prodObj, devObj) {
6104
+ const prodProps = new Map(prodObj.properties.map((p) => [p.key.name || p.key.value, p]));
6105
+ for (const prop of devObj.properties) {
6106
+ const key = prop.key.name || prop.key.value;
6107
+ if (prodProps.has(key)) {
6108
+ const index = prodObj.properties.indexOf(prodProps.get(key));
6109
+ if (index >= 0)
6110
+ prodObj.properties[index] = prop;
6111
+ } else {
6112
+ prodObj.properties.push(prop);
6113
+ }
6114
+ }
6115
+ }
6116
+ async function generateScript(options, mode, base2) {
6117
+ const { dir, fileName, globalName, serve, build } = options.env;
6118
+ const folder = await findFolder(import_node_process3.default.cwd(), dir);
6119
+ const files = await (0, import_fast_glob.default)("*.+(js|ts)", {
6120
+ absolute: true,
6121
+ cwd: folder
6122
+ });
6123
+ const testReg = mode === "serve" ? serve : build;
6124
+ let target = "";
6125
+ let source = "";
6126
+ let code = "";
6127
+ const name = fileName;
6128
+ for (const file of files) {
6129
+ try {
6130
+ const mod = await import_node_fs2.promises.readFile(file, "utf-8");
6131
+ if (testReg?.test(file))
6132
+ target = mod;
6133
+ else
6134
+ source = mod;
6135
+ } catch (error) {
6136
+ console.error(`Error loading file ${file}:`, error);
6137
+ }
6138
+ }
6139
+ const targetAst = import_recast.default.parse(target);
6140
+ const sourceAst = import_recast.default.parse(source);
6141
+ const targetExport = targetAst.program.body.find((n) => n.type === "ExportDefaultDeclaration").declaration;
6142
+ const sourceExport = sourceAst.program.body.find((n) => n.type === "ExportDefaultDeclaration").declaration;
6143
+ mergeObjects(sourceExport, targetExport);
6144
+ const mergedCode = import_recast.default.print(sourceExport).code;
6145
+ const returnedTarget = mergedCode;
6146
+ const versionInfo = await generateVersion(options, mode);
6147
+ code = `window.${globalName}=${returnedTarget};
6148
+ ${versionInfo}`;
6149
+ const formatCode = code;
6150
+ return {
6151
+ code,
6152
+ script: ` <script type="text/javascript" src="${base2}${fileName}"></script>
6153
+ </head>`,
6154
+ emit: {
6155
+ type: "asset",
6156
+ fileName: name,
6157
+ source: formatCode
6158
+ },
6159
+ watchFiles: files
6160
+ };
6161
+ }
6162
+ async function generateVersion(options, mode) {
6163
+ const pkg = await (0, import_local_pkg.getPackageInfo)(import_node_process3.default.cwd());
6164
+ return `console.info("Version: %c${pkg?.version}%c - ${mode === "serve" ? "runtime" : "built"} on %c${options.date}%c", "color: green;", '', "color: blue;", '')`;
6165
+ }
6166
+ async function findFolder(directoryPath, dir) {
6167
+ const ignore = /* @__PURE__ */ new Set(["dist", "node_modules", "playground", "example", "test", "jest", "tests", "locales", "public", ".git", ".github", ".vscode"]);
6168
+ const files = await import_node_fs2.promises.readdir(directoryPath);
6169
+ const filePaths = files.filter((item) => !ignore.has(item));
6170
+ let nestedFolder = "";
6171
+ for (const file of filePaths) {
6172
+ const fullFilePath = import_node_path2.default.join(directoryPath, file);
6173
+ const stat = await import_node_fs2.promises.stat(fullFilePath);
6174
+ if (stat.isDirectory()) {
6175
+ if (file.toLowerCase() === dir) {
6176
+ return fullFilePath;
6177
+ } else {
6178
+ nestedFolder = await findFolder(fullFilePath, dir);
6179
+ if (nestedFolder)
6180
+ return nestedFolder;
6181
+ }
6182
+ }
6183
+ }
6184
+ return "";
6185
+ }
6186
+
6187
+ // src/core/options.ts
6188
+ var import_utils = require("@antfu/utils");
6189
+ function resolveOptions(options) {
6190
+ const defaults = {
6191
+ env: {
6192
+ dir: "config",
6193
+ fileName: "manifest.js",
6194
+ globalName: "manifest",
6195
+ serve: /dev/i,
6196
+ build: /prod/i
6197
+ },
6198
+ compress: {
6199
+ outDir: "dist",
6200
+ ignoreBase: true
6201
+ }
6202
+ };
6203
+ const mergeOptions = (0, import_utils.deepMerge)(defaults, options);
6204
+ const formatter = new Intl.DateTimeFormat("zh-CN", {
6205
+ dateStyle: "full",
6206
+ timeStyle: "medium"
6207
+ });
6208
+ return {
6209
+ ...mergeOptions,
6210
+ date: formatter.format(/* @__PURE__ */ new Date())
6211
+ };
6212
+ }
6213
+
6213
6214
  // src/index.ts
6214
6215
  var virtualEnvId = "virtual:env";
6215
6216
  var resolvedVirtualEnvId = `\0${virtualEnvId}`;
@@ -6289,7 +6290,7 @@ var nuxt_default = (0, import_kit.defineNuxtModule)({
6289
6290
  defaults: {
6290
6291
  // ...default options
6291
6292
  },
6292
- setup(options, nuxt) {
6293
+ setup(options, _nuxt) {
6293
6294
  (0, import_kit.addVitePlugin)(() => vite_default(options));
6294
6295
  (0, import_kit.addWebpackPlugin)(() => webpack_default(options));
6295
6296
  }
package/dist/nuxt.js CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  import {
7
7
  vite_default
8
- } from "./chunk-JDYYGKOJ.js";
8
+ } from "./chunk-Y45ERLIW.js";
9
9
  import {
10
10
  webpack_default
11
- } from "./chunk-OQXUTP45.js";
12
- import "./chunk-U7BMFDAG.js";
11
+ } from "./chunk-ELYQVJHH.js";
12
+ import "./chunk-QWCQIGEO.js";
13
13
 
14
14
  // src/nuxt.ts
15
15
  import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
@@ -22,7 +22,7 @@ var nuxt_default = defineNuxtModule({
22
22
  defaults: {
23
23
  // ...default options
24
24
  },
25
- setup(options, nuxt) {
25
+ setup(options, _nuxt) {
26
26
  addVitePlugin(() => vite_default(options));
27
27
  addWebpackPlugin(() => webpack_default(options));
28
28
  }