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/vite.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
  };
@@ -5541,127 +5541,10 @@ var import_node_fs3 = require("fs");
5541
5541
  var import_node_process4 = __toESM(require("process"), 1);
5542
5542
  var import_unplugin = require("unplugin");
5543
5543
 
5544
- // src/core/generate.ts
5545
- var import_node_path = __toESM(require("path"), 1);
5546
- var import_node_fs = require("fs");
5547
- var import_node_process = __toESM(require("process"), 1);
5548
- var import_fast_glob = __toESM(require_out4(), 1);
5549
- var import_recast = __toESM(require("recast"), 1);
5550
- function mergeObjects(prodObj, devObj) {
5551
- const prodProps = new Map(prodObj.properties.map((p) => [p.key.name || p.key.value, p]));
5552
- for (const prop of devObj.properties) {
5553
- const key = prop.key.name || prop.key.value;
5554
- if (prodProps.has(key)) {
5555
- const index = prodObj.properties.indexOf(prodProps.get(key));
5556
- if (index >= 0)
5557
- prodObj.properties[index] = prop;
5558
- } else {
5559
- prodObj.properties.push(prop);
5560
- }
5561
- }
5562
- }
5563
- async function generateScript(options, mode, base2) {
5564
- const { dir, fileName, globalName, serve, build } = options.env;
5565
- const folder = await findFolder(import_node_process.default.cwd(), dir);
5566
- const files = await (0, import_fast_glob.default)("*.+(js|ts)", {
5567
- absolute: true,
5568
- cwd: folder
5569
- });
5570
- const testReg = mode === "serve" ? serve : build;
5571
- let target = "";
5572
- let source = "";
5573
- let code = "";
5574
- const name = fileName;
5575
- for (const file of files) {
5576
- try {
5577
- const mod = await import_node_fs.promises.readFile(file, "utf-8");
5578
- if (testReg == null ? void 0 : testReg.test(file))
5579
- target = mod;
5580
- else
5581
- source = mod;
5582
- } catch (error) {
5583
- console.error(`Error loading file ${file}:`, error);
5584
- }
5585
- }
5586
- const targetAst = import_recast.default.parse(target);
5587
- const sourceAst = import_recast.default.parse(source);
5588
- const targetExport = targetAst.program.body.find((n) => n.type === "ExportDefaultDeclaration").declaration;
5589
- const sourceExport = sourceAst.program.body.find((n) => n.type === "ExportDefaultDeclaration").declaration;
5590
- mergeObjects(sourceExport, targetExport);
5591
- const mergedCode = import_recast.default.print(sourceExport).code;
5592
- const returnedTarget = mergedCode;
5593
- const versionInfo = await generateVersion(options, mode);
5594
- code = `window.${globalName}=${returnedTarget};${versionInfo}`;
5595
- const formatCode = code;
5596
- return {
5597
- code,
5598
- script: ` <script type="text/javascript" src="${base2}${fileName}"></script>
5599
- </head>`,
5600
- emit: {
5601
- type: "asset",
5602
- fileName: name,
5603
- source: formatCode
5604
- },
5605
- watchFiles: files
5606
- };
5607
- }
5608
- async function generateVersion(options, mode) {
5609
- const packageFile = await (0, import_fast_glob.default)("package.json", {
5610
- absolute: true,
5611
- cwd: (0, import_node_path.resolve)(import_node_process.default.cwd())
5612
- });
5613
- const packageString = await import_node_fs.promises.readFile(packageFile[0], "utf8");
5614
- const packageJson = JSON.parse(packageString);
5615
- return `console.info("Version: ${packageJson.version} - ${mode === "serve" ? "runtime" : "built"} on ${options.date}")`;
5616
- }
5617
- async function findFolder(directoryPath, dir) {
5618
- const ignore = /* @__PURE__ */ new Set(["dist", "node_modules", "playground", "example", "test", "jest", "tests", "locales", "public", ".git", ".github", ".vscode"]);
5619
- const files = await import_node_fs.promises.readdir(directoryPath);
5620
- const filePaths = files.filter((item) => !ignore.has(item));
5621
- let nestedFolder = "";
5622
- for (const file of filePaths) {
5623
- const fullFilePath = import_node_path.default.join(directoryPath, file);
5624
- const stat = await import_node_fs.promises.stat(fullFilePath);
5625
- if (stat.isDirectory()) {
5626
- if (file.toLowerCase() === dir) {
5627
- return fullFilePath;
5628
- } else {
5629
- nestedFolder = await findFolder(fullFilePath, dir);
5630
- if (nestedFolder)
5631
- return nestedFolder;
5632
- }
5633
- }
5634
- }
5635
- return "";
5636
- }
5637
-
5638
- // src/core/options.ts
5639
- var import_utils = require("@antfu/utils");
5640
- function resolveOptions(options) {
5641
- const defaults = {
5642
- env: {
5643
- dir: "config",
5644
- fileName: "manifest.js",
5645
- globalName: "manifest",
5646
- serve: /dev|development/i,
5647
- build: /prod|production/i
5648
- },
5649
- compress: {
5650
- outDir: "dist",
5651
- ignoreBase: true
5652
- }
5653
- };
5654
- const mergeOptions = (0, import_utils.deepMerge)(defaults, options);
5655
- return {
5656
- ...mergeOptions,
5657
- date: (/* @__PURE__ */ new Date()).toLocaleString()
5658
- };
5659
- }
5660
-
5661
5544
  // src/core/compress.ts
5662
- var import_node_fs2 = __toESM(require("fs"), 1);
5663
- var import_node_path2 = __toESM(require("path"), 1);
5664
- var import_node_process3 = __toESM(require("process"), 1);
5545
+ var import_node_fs = __toESM(require("fs"), 1);
5546
+ var import_node_path = __toESM(require("path"), 1);
5547
+ var import_node_process2 = __toESM(require("process"), 1);
5665
5548
  var import_archiver = __toESM(require("archiver"), 1);
5666
5549
 
5667
5550
  // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/ansi-styles/index.js
@@ -5851,16 +5734,16 @@ var ansiStyles = assembleStyles();
5851
5734
  var ansi_styles_default = ansiStyles;
5852
5735
 
5853
5736
  // node_modules/.pnpm/chalk@5.6.2/node_modules/chalk/source/vendor/supports-color/index.js
5854
- var import_node_process2 = __toESM(require("process"), 1);
5737
+ var import_node_process = __toESM(require("process"), 1);
5855
5738
  var import_node_os = __toESM(require("os"), 1);
5856
5739
  var import_node_tty = __toESM(require("tty"), 1);
5857
- function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process2.default.argv) {
5740
+ function hasFlag(flag, argv = globalThis.Deno ? globalThis.Deno.args : import_node_process.default.argv) {
5858
5741
  const prefix = flag.startsWith("-") ? "" : flag.length === 1 ? "-" : "--";
5859
5742
  const position = argv.indexOf(prefix + flag);
5860
5743
  const terminatorPosition = argv.indexOf("--");
5861
5744
  return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
5862
5745
  }
5863
- var { env } = import_node_process2.default;
5746
+ var { env } = import_node_process.default;
5864
5747
  var flagForceColor;
5865
5748
  if (hasFlag("no-color") || hasFlag("no-colors") || hasFlag("color=false") || hasFlag("color=never")) {
5866
5749
  flagForceColor = 0;
@@ -5916,7 +5799,7 @@ function _supportsColor(haveStream, { streamIsTTY, sniffFlags = true } = {}) {
5916
5799
  if (env.TERM === "dumb") {
5917
5800
  return min;
5918
5801
  }
5919
- if (import_node_process2.default.platform === "win32") {
5802
+ if (import_node_process.default.platform === "win32") {
5920
5803
  const osRelease = import_node_os.default.release().split(".");
5921
5804
  if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
5922
5805
  return Number(osRelease[2]) >= 14931 ? 3 : 2;
@@ -6176,15 +6059,15 @@ var Log = class {
6176
6059
  // src/core/compress.ts
6177
6060
  async function createCompress(options) {
6178
6061
  const { outDir, ignoreBase } = options;
6179
- const zipFilePath = import_node_path2.default.resolve(import_node_process3.default.cwd(), `${import_node_path2.default.basename(outDir)}.zip`);
6062
+ const zipFilePath = import_node_path.default.resolve(import_node_process2.default.cwd(), `${import_node_path.default.basename(outDir)}.zip`);
6180
6063
  Log.log("Compressing the directory", outDir);
6181
- return new Promise((resolve2, reject) => {
6064
+ return new Promise((resolve, reject) => {
6182
6065
  try {
6183
- const output = import_node_fs2.default.createWriteStream(zipFilePath);
6066
+ const output = import_node_fs.default.createWriteStream(zipFilePath);
6184
6067
  const archive = (0, import_archiver.default)("zip");
6185
6068
  output.on("close", () => {
6186
- Log.success("Successfully compressed to", `${zipFilePath} (${archive.pointer() / 1024 / 1024} MB)`);
6187
- resolve2(null);
6069
+ Log.success("Successfully compressed to", `${zipFilePath} (${(archive.pointer() / 1024 / 1024).toFixed(1)} MB)`);
6070
+ resolve(null);
6188
6071
  });
6189
6072
  archive.on("warning", (err) => {
6190
6073
  if (err.code === "ENOENT")
@@ -6197,8 +6080,8 @@ async function createCompress(options) {
6197
6080
  reject(err);
6198
6081
  });
6199
6082
  archive.pipe(output);
6200
- const absoluteOutDir = import_node_path2.default.resolve(outDir);
6201
- archive.directory(absoluteOutDir, ignoreBase ? false : import_node_path2.default.basename(outDir));
6083
+ const absoluteOutDir = import_node_path.default.resolve(outDir);
6084
+ archive.directory(absoluteOutDir, ignoreBase ? false : import_node_path.default.basename(outDir));
6202
6085
  archive.finalize();
6203
6086
  } catch (error) {
6204
6087
  Log.error("Error compressing the directory", error);
@@ -6207,6 +6090,124 @@ async function createCompress(options) {
6207
6090
  });
6208
6091
  }
6209
6092
 
6093
+ // src/core/generate.ts
6094
+ var import_node_fs2 = require("fs");
6095
+ var import_node_path2 = __toESM(require("path"), 1);
6096
+ var import_node_process3 = __toESM(require("process"), 1);
6097
+ var import_fast_glob = __toESM(require_out4(), 1);
6098
+ var import_local_pkg = require("local-pkg");
6099
+ var import_recast = __toESM(require("recast"), 1);
6100
+ function mergeObjects(prodObj, devObj) {
6101
+ const prodProps = new Map(prodObj.properties.map((p) => [p.key.name || p.key.value, p]));
6102
+ for (const prop of devObj.properties) {
6103
+ const key = prop.key.name || prop.key.value;
6104
+ if (prodProps.has(key)) {
6105
+ const index = prodObj.properties.indexOf(prodProps.get(key));
6106
+ if (index >= 0)
6107
+ prodObj.properties[index] = prop;
6108
+ } else {
6109
+ prodObj.properties.push(prop);
6110
+ }
6111
+ }
6112
+ }
6113
+ async function generateScript(options, mode, base2) {
6114
+ const { dir, fileName, globalName, serve, build } = options.env;
6115
+ const folder = await findFolder(import_node_process3.default.cwd(), dir);
6116
+ const files = await (0, import_fast_glob.default)("*.+(js|ts)", {
6117
+ absolute: true,
6118
+ cwd: folder
6119
+ });
6120
+ const testReg = mode === "serve" ? serve : build;
6121
+ let target = "";
6122
+ let source = "";
6123
+ let code = "";
6124
+ const name = fileName;
6125
+ for (const file of files) {
6126
+ try {
6127
+ const mod = await import_node_fs2.promises.readFile(file, "utf-8");
6128
+ if (testReg?.test(file))
6129
+ target = mod;
6130
+ else
6131
+ source = mod;
6132
+ } catch (error) {
6133
+ console.error(`Error loading file ${file}:`, error);
6134
+ }
6135
+ }
6136
+ const targetAst = import_recast.default.parse(target);
6137
+ const sourceAst = import_recast.default.parse(source);
6138
+ const targetExport = targetAst.program.body.find((n) => n.type === "ExportDefaultDeclaration").declaration;
6139
+ const sourceExport = sourceAst.program.body.find((n) => n.type === "ExportDefaultDeclaration").declaration;
6140
+ mergeObjects(sourceExport, targetExport);
6141
+ const mergedCode = import_recast.default.print(sourceExport).code;
6142
+ const returnedTarget = mergedCode;
6143
+ const versionInfo = await generateVersion(options, mode);
6144
+ code = `window.${globalName}=${returnedTarget};
6145
+ ${versionInfo}`;
6146
+ const formatCode = code;
6147
+ return {
6148
+ code,
6149
+ script: ` <script type="text/javascript" src="${base2}${fileName}"></script>
6150
+ </head>`,
6151
+ emit: {
6152
+ type: "asset",
6153
+ fileName: name,
6154
+ source: formatCode
6155
+ },
6156
+ watchFiles: files
6157
+ };
6158
+ }
6159
+ async function generateVersion(options, mode) {
6160
+ const pkg = await (0, import_local_pkg.getPackageInfo)(import_node_process3.default.cwd());
6161
+ return `console.info("Version: %c${pkg?.version}%c - ${mode === "serve" ? "runtime" : "built"} on %c${options.date}%c", "color: green;", '', "color: blue;", '')`;
6162
+ }
6163
+ async function findFolder(directoryPath, dir) {
6164
+ const ignore = /* @__PURE__ */ new Set(["dist", "node_modules", "playground", "example", "test", "jest", "tests", "locales", "public", ".git", ".github", ".vscode"]);
6165
+ const files = await import_node_fs2.promises.readdir(directoryPath);
6166
+ const filePaths = files.filter((item) => !ignore.has(item));
6167
+ let nestedFolder = "";
6168
+ for (const file of filePaths) {
6169
+ const fullFilePath = import_node_path2.default.join(directoryPath, file);
6170
+ const stat = await import_node_fs2.promises.stat(fullFilePath);
6171
+ if (stat.isDirectory()) {
6172
+ if (file.toLowerCase() === dir) {
6173
+ return fullFilePath;
6174
+ } else {
6175
+ nestedFolder = await findFolder(fullFilePath, dir);
6176
+ if (nestedFolder)
6177
+ return nestedFolder;
6178
+ }
6179
+ }
6180
+ }
6181
+ return "";
6182
+ }
6183
+
6184
+ // src/core/options.ts
6185
+ var import_utils = require("@antfu/utils");
6186
+ function resolveOptions(options) {
6187
+ const defaults = {
6188
+ env: {
6189
+ dir: "config",
6190
+ fileName: "manifest.js",
6191
+ globalName: "manifest",
6192
+ serve: /dev/i,
6193
+ build: /prod/i
6194
+ },
6195
+ compress: {
6196
+ outDir: "dist",
6197
+ ignoreBase: true
6198
+ }
6199
+ };
6200
+ const mergeOptions = (0, import_utils.deepMerge)(defaults, options);
6201
+ const formatter = new Intl.DateTimeFormat("zh-CN", {
6202
+ dateStyle: "full",
6203
+ timeStyle: "medium"
6204
+ });
6205
+ return {
6206
+ ...mergeOptions,
6207
+ date: formatter.format(/* @__PURE__ */ new Date())
6208
+ };
6209
+ }
6210
+
6210
6211
  // src/index.ts
6211
6212
  var virtualEnvId = "virtual:env";
6212
6213
  var resolvedVirtualEnvId = `\0${virtualEnvId}`;
package/dist/vite.js CHANGED
@@ -5,8 +5,8 @@
5
5
 
6
6
  import {
7
7
  vite_default
8
- } from "./chunk-JDYYGKOJ.js";
9
- import "./chunk-U7BMFDAG.js";
8
+ } from "./chunk-Y45ERLIW.js";
9
+ import "./chunk-QWCQIGEO.js";
10
10
  export {
11
11
  vite_default as default
12
12
  };