@supsign/unplugin-interfaces 1.1.0 → 1.1.2

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/astro.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { r as unplugin } from "./src-BBWM3Bz4.mjs";
1
+ import { r as unplugin } from "./src-75zMdGMB.mjs";
2
2
  //#region src/astro.ts
3
3
  var astro_default = (options) => ({
4
4
  name: "unplugin-starter",
package/dist/esbuild.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as unpluginFactory } from "./src-BBWM3Bz4.mjs";
1
+ import { i as unpluginFactory } from "./src-75zMdGMB.mjs";
2
2
  import { createEsbuildPlugin } from "unplugin";
3
3
  //#region src/esbuild.ts
4
4
  var esbuild_default = createEsbuildPlugin(unpluginFactory);
package/dist/farm.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as unpluginFactory } from "./src-BBWM3Bz4.mjs";
1
+ import { i as unpluginFactory } from "./src-75zMdGMB.mjs";
2
2
  import { createFarmPlugin } from "unplugin";
3
3
  //#region src/farm.ts
4
4
  var farm_default = createFarmPlugin(unpluginFactory);
package/dist/index.mjs CHANGED
@@ -1,2 +1,2 @@
1
- import { a as vite, i as unpluginFactory, n as rollup, o as webpack, r as unplugin, t as esbuild } from "./src-BBWM3Bz4.mjs";
1
+ import { a as vite, i as unpluginFactory, n as rollup, o as webpack, r as unplugin, t as esbuild } from "./src-75zMdGMB.mjs";
2
2
  export { unplugin as default, unplugin, esbuild, rollup, unpluginFactory, vite, webpack };
package/dist/nuxt.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import "./src-BBWM3Bz4.mjs";
1
+ import "./src-75zMdGMB.mjs";
2
2
  import vite_default from "./vite.mjs";
3
3
  import webpack_default from "./webpack.mjs";
4
4
  import { addVitePlugin, addWebpackPlugin, defineNuxtModule } from "@nuxt/kit";
package/dist/rollup.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as unpluginFactory } from "./src-BBWM3Bz4.mjs";
1
+ import { i as unpluginFactory } from "./src-75zMdGMB.mjs";
2
2
  import { createRollupPlugin } from "unplugin";
3
3
  //#region src/rollup.ts
4
4
  var rollup_default = createRollupPlugin(unpluginFactory);
package/dist/rspack.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as unpluginFactory } from "./src-BBWM3Bz4.mjs";
1
+ import { i as unpluginFactory } from "./src-75zMdGMB.mjs";
2
2
  import { createRspackPlugin } from "unplugin";
3
3
  //#region src/rspack.ts
4
4
  var rspack_default = createRspackPlugin(unpluginFactory);
@@ -1603,22 +1603,31 @@ const RE_INTERFACE = /^export\s+interface\s+([A-Za-z_$][\w$]*)/gm;
1603
1603
  const RE_NAMED_EXPORT = /export\s*\{([^}]+)\}/g;
1604
1604
  const RE_TYPE_EXPORT = /export\s+type\s*\{([^}]+)\}/g;
1605
1605
  const RE_AS_SPLIT = /\s+as\s+/;
1606
- function generateInterfaces(opts) {
1606
+ function parseNames(content) {
1607
+ const interfaceNames = [...content.matchAll(RE_INTERFACE)].map((match) => match[1]);
1608
+ const namedExportNames = [...content.matchAll(RE_NAMED_EXPORT)].filter((match) => !content.substring(Math.max(0, match.index - 10), match.index).includes("type")).flatMap((match) => match[1].split(",").map((item) => item.trim().split(RE_AS_SPLIT)[0].trim()).filter((name) => name.length > 0));
1609
+ const typeExportNames = [...content.matchAll(RE_TYPE_EXPORT)].flatMap((match) => match[1].split(",").map((item) => item.trim().split(RE_AS_SPLIT)[0].trim()).filter((name) => name.length > 0));
1610
+ return [...new Set([
1611
+ ...interfaceNames,
1612
+ ...namedExportNames,
1613
+ ...typeExportNames
1614
+ ])].filter((name) => name && name !== "export");
1615
+ }
1616
+ async function generateInterfaces(opts) {
1607
1617
  const { interfaceDir, outputFile, excludeFiles } = opts;
1608
- const files = fs.readdirSync(interfaceDir).filter((file) => file.endsWith(".ts") && file !== "index.ts" && !excludeFiles.has(file));
1618
+ const files = (await fs.promises.readdir(interfaceDir)).filter((file) => file.endsWith(".ts") && file !== "index.ts" && !excludeFiles.has(file));
1619
+ try {
1620
+ const outputMtime = (await fs.promises.stat(outputFile)).mtimeMs;
1621
+ if ((await Promise.all(files.map((file) => fs.promises.stat(path.join(interfaceDir, file)).then((stat) => stat.mtimeMs)))).every((mtime) => mtime <= outputMtime)) return {
1622
+ files: files.length,
1623
+ interfaces: 0,
1624
+ skipped: true
1625
+ };
1626
+ } catch {}
1627
+ const contents = await Promise.all(files.map((file) => fs.promises.readFile(path.join(interfaceDir, file), "utf8")));
1609
1628
  const interfaces = [];
1610
- for (const file of files) {
1611
- const filePath = path.join(interfaceDir, file);
1612
- const content = fs.readFileSync(filePath, "utf8");
1613
- const interfaceNames = [...content.matchAll(RE_INTERFACE)].map((match) => match[1]);
1614
- const namedExportNames = [...content.matchAll(RE_NAMED_EXPORT)].filter((match) => !content.substring(Math.max(0, match.index - 10), match.index).includes("type")).flatMap((match) => match[1].split(",").map((item) => item.trim().split(RE_AS_SPLIT)[0].trim()).filter((name) => name.length > 0));
1615
- const typeExportNames = [...content.matchAll(RE_TYPE_EXPORT)].flatMap((match) => match[1].split(",").map((item) => item.trim().split(RE_AS_SPLIT)[0].trim()).filter((name) => name.length > 0));
1616
- const allNames = [
1617
- ...interfaceNames,
1618
- ...namedExportNames,
1619
- ...typeExportNames
1620
- ];
1621
- const names = [...new Set(allNames)].filter((name) => name && name !== "export");
1629
+ for (const [idx, file] of files.entries()) {
1630
+ const names = parseNames(contents[idx]);
1622
1631
  if (names.length) interfaces.push({
1623
1632
  file,
1624
1633
  names
@@ -1632,8 +1641,8 @@ function generateInterfaces(opts) {
1632
1641
  "export {};",
1633
1642
  ""
1634
1643
  ];
1635
- fs.mkdirSync(path.dirname(outputFile), { recursive: true });
1636
- fs.writeFileSync(outputFile, globalLines.join("\n"), "utf8");
1644
+ await fs.promises.mkdir(path.dirname(outputFile), { recursive: true });
1645
+ await fs.promises.writeFile(outputFile, globalLines.join("\n"), "utf8");
1637
1646
  return {
1638
1647
  files: files.length,
1639
1648
  interfaces: interfaces.flatMap((iface) => iface.names).length
@@ -1652,30 +1661,31 @@ function resolveOptions(root, options = {}) {
1652
1661
  //#region src/index.ts
1653
1662
  const unpluginFactory = (userOptions = {}, meta) => {
1654
1663
  const opts = resolveOptions(meta.framework === "vite" ? meta?.vite?.server?.config?.root ?? process$1.cwd() : process$1.cwd(), userOptions);
1664
+ let isDevServer = false;
1655
1665
  return {
1656
1666
  name: "@supsign/unplugin-interfaces",
1657
- buildStart() {
1658
- const result = generateInterfaces(opts);
1667
+ async buildStart() {
1668
+ if (isDevServer) return;
1669
+ const result = await generateInterfaces(opts);
1659
1670
  this.info(`Generated ${result.interfaces} interfaces from ${result.files} files`);
1660
1671
  },
1661
1672
  vite: { configureServer(server) {
1673
+ isDevServer = true;
1674
+ generateInterfaces(opts).then((result) => {
1675
+ server.config.logger.info(`@supsign/unplugin-interfaces: Generated ${result.interfaces} interfaces from ${result.files} files`, { timestamp: true });
1676
+ });
1662
1677
  const watcher = chokidar_default.watch(opts.interfaceDir, {
1663
1678
  ignored: (filePath) => filePath.endsWith("index.ts") || filePath.endsWith(".d.ts") || [...opts.excludeFiles].some((filename) => filePath.endsWith(filename)),
1664
1679
  ignoreInitial: true
1665
1680
  });
1666
1681
  const log = (action) => {
1667
- const result = generateInterfaces(opts);
1668
- server.config.logger.info(`${action}: ${result.interfaces} interfaces from ${result.files} files`, { timestamp: true });
1682
+ generateInterfaces(opts).then((result) => {
1683
+ server.config.logger.info(`${action}: ${result.interfaces} interfaces from ${result.files} files`, { timestamp: true });
1684
+ });
1669
1685
  };
1670
1686
  watcher.on("add", () => log("Added file, regenerated")).on("change", () => log("Updated file, regenerated")).on("unlink", () => log("Removed file, regenerated"));
1671
1687
  server.watcher.on("close", () => watcher.close());
1672
- } },
1673
- transformInclude(id) {
1674
- return id.endsWith("main.ts");
1675
- },
1676
- transform(code) {
1677
- return code.replace("__UNPLUGIN__", "Hello Unplugin!");
1678
- }
1688
+ } }
1679
1689
  };
1680
1690
  };
1681
1691
  const unplugin = /* @__PURE__ */ createUnplugin(unpluginFactory);
package/dist/vite.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as unpluginFactory } from "./src-BBWM3Bz4.mjs";
1
+ import { i as unpluginFactory } from "./src-75zMdGMB.mjs";
2
2
  import { createVitePlugin } from "unplugin";
3
3
  //#region src/vite.ts
4
4
  var vite_default = createVitePlugin(unpluginFactory);
package/dist/webpack.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { i as unpluginFactory } from "./src-BBWM3Bz4.mjs";
1
+ import { i as unpluginFactory } from "./src-75zMdGMB.mjs";
2
2
  import { createWebpackPlugin } from "unplugin";
3
3
  //#region src/webpack.ts
4
4
  var webpack_default = createWebpackPlugin(unpluginFactory);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@supsign/unplugin-interfaces",
3
- "version": "1.1.0",
3
+ "version": "1.1.2",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "rollup",
@@ -22,9 +22,9 @@
22
22
  "dist"
23
23
  ],
24
24
  "type": "module",
25
- "main": "./dist/index.js",
26
- "module": "./dist/index.js",
27
- "types": "./dist/index.d.ts",
25
+ "main": "./dist/index.mjs",
26
+ "module": "./dist/index.mjs",
27
+ "types": "./dist/index.d.mts",
28
28
  "typesVersions": {
29
29
  "*": {
30
30
  "*": [
@@ -34,28 +34,31 @@
34
34
  }
35
35
  },
36
36
  "exports": {
37
- ".": "./dist/index.js",
38
- "./astro": "./dist/astro.js",
39
- "./esbuild": "./dist/esbuild.js",
40
- "./farm": "./dist/farm.js",
41
- "./nuxt": "./dist/nuxt.js",
42
- "./rollup": "./dist/rollup.js",
43
- "./rspack": "./dist/rspack.js",
44
- "./types": "./dist/types.js",
45
- "./vite": "./dist/vite.js",
46
- "./webpack": "./dist/webpack.js",
37
+ ".": "./dist/index.mjs",
38
+ "./astro": "./dist/astro.mjs",
39
+ "./esbuild": "./dist/esbuild.mjs",
40
+ "./farm": "./dist/farm.mjs",
41
+ "./nuxt": "./dist/nuxt.mjs",
42
+ "./rollup": "./dist/rollup.mjs",
43
+ "./rspack": "./dist/rspack.mjs",
44
+ "./types": "./dist/types.mjs",
45
+ "./vite": "./dist/vite.mjs",
46
+ "./webpack": "./dist/webpack.mjs",
47
47
  "./package.json": "./package.json"
48
48
  },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
49
52
  "dependencies": {
50
53
  "unplugin": "^3.0.0"
51
54
  },
52
55
  "devDependencies": {
53
56
  "@nuxt/kit": "^4.4.2",
54
- "esbuild": "^0.27.0",
55
57
  "@nuxt/schema": "^4.4.2",
56
58
  "@types/node": "^25.5.0",
57
59
  "bumpp": "^11.0.1",
58
60
  "chokidar": "^5.0.0",
61
+ "esbuild": "^0.27.0",
59
62
  "nodemon": "^3.1.14",
60
63
  "oxfmt": "^0.40.0",
61
64
  "oxlint": "^1.55.0",