@animus-ui/next-plugin 0.1.0-next.30 → 0.1.0-next.31

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/index.mjs CHANGED
@@ -1,6 +1,6 @@
1
1
  import { a as setManifestJson, i as setAnalysisPromise, o as __require, r as resetAnalysisPromise, t as getAnalysisPromise } from "./singleton-BZ7W87Ir.mjs";
2
2
  import { existsSync, mkdirSync, readFileSync, readdirSync, statSync, writeFileSync } from "fs";
3
- import { extname, join, relative, resolve } from "path";
3
+ import { dirname, extname, join, relative, resolve, sep } from "path";
4
4
  import { createHash } from "crypto";
5
5
  import { tmpdir } from "os";
6
6
  import { applyPrefix, applyUnitFallback, detectRuntime, execSubprocess, extractSystemFilePackages, resolveGlobalStyles } from "@animus-ui/extract/pipeline";
@@ -19,6 +19,8 @@ var AnimusWebpackPlugin = class {
19
19
  systemResolveScript = null;
20
20
  fileCache = /* @__PURE__ */ new Map();
21
21
  lastCssHash = null;
22
+ externalPackageDirs = [];
23
+ externalSourceEntries = /* @__PURE__ */ new Map();
22
24
  constructor(options) {
23
25
  this.options = options;
24
26
  }
@@ -131,6 +133,45 @@ var AnimusWebpackPlugin = class {
131
133
  }
132
134
  const packageNames = extractSystemFilePackages(resolvedSystemPath);
133
135
  const packageMap = this.resolvePackagesByName(rootDir, packageNames);
136
+ const excludePatternsForPkgs = [
137
+ "dist",
138
+ ".test.",
139
+ ".spec."
140
+ ];
141
+ const collectedPkgDirs = [];
142
+ this.externalSourceEntries.clear();
143
+ for (const [specifier, entryRelPath] of Object.entries(packageMap)) {
144
+ const absEntry = resolve(rootDir, entryRelPath);
145
+ let pkgRoot = dirname(absEntry);
146
+ while (pkgRoot !== dirname(pkgRoot) && !existsSync(join(pkgRoot, "package.json"))) pkgRoot = dirname(pkgRoot);
147
+ const srcDir = join(pkgRoot, "src");
148
+ if (existsSync(srcDir)) {
149
+ collectedPkgDirs.push(srcDir);
150
+ const srcEntry = join(srcDir, "index.ts");
151
+ if (existsSync(srcEntry)) {
152
+ packageMap[specifier] = relative(rootDir, srcEntry);
153
+ this.externalSourceEntries.set(specifier, srcEntry);
154
+ }
155
+ const pkgFiles = this.discoverFiles(srcDir, rootDir, excludePatternsForPkgs);
156
+ for (const pkgFile of pkgFiles) {
157
+ const pkgRelPath = relative(rootDir, pkgFile);
158
+ if (!fileEntries.some((e) => e.path === pkgRelPath)) try {
159
+ const pkgSource = readFileSync(pkgFile, "utf-8");
160
+ const pkgHash = createHash("md5").update(pkgSource).digest("hex");
161
+ this.fileCache.set(pkgRelPath, {
162
+ hash: pkgHash,
163
+ source: pkgSource
164
+ });
165
+ fileEntries.push({
166
+ path: pkgRelPath,
167
+ source: pkgSource,
168
+ hash: pkgHash
169
+ });
170
+ } catch {}
171
+ }
172
+ } else collectedPkgDirs.push(dirname(absEntry));
173
+ }
174
+ this.externalPackageDirs = collectedPkgDirs;
134
175
  const { analyzeProject } = __require("@animus-ui/extract");
135
176
  const animusDirPath = join(rootDir, ".animus");
136
177
  const emitterConfig = JSON.stringify({
@@ -274,6 +315,7 @@ var AnimusWebpackPlugin = class {
274
315
  resolvePackagesByName(rootDir, names) {
275
316
  if (names.length === 0) return {};
276
317
  const nameSet = new Set(names);
318
+ const resolved = /* @__PURE__ */ new Set();
277
319
  const packageMap = {};
278
320
  try {
279
321
  const workspaces = JSON.parse(readFileSync(join(rootDir, "package.json"), "utf-8")).workspaces || [];
@@ -285,11 +327,20 @@ var AnimusWebpackPlugin = class {
285
327
  const name = pkg.name || "";
286
328
  if (nameSet.has(name)) {
287
329
  const entryPath = resolve(wsDir, pkg.main || pkg.module || "index.ts");
288
- if (existsSync(entryPath)) packageMap[name] = relative(rootDir, entryPath);
330
+ if (existsSync(entryPath)) {
331
+ packageMap[name] = relative(rootDir, entryPath);
332
+ resolved.add(name);
333
+ }
289
334
  }
290
335
  } catch {}
291
336
  }
292
337
  } catch {}
338
+ for (const name of nameSet) {
339
+ if (resolved.has(name)) continue;
340
+ try {
341
+ packageMap[name] = relative(rootDir, __require.resolve(name, { paths: [rootDir] }));
342
+ } catch {}
343
+ }
293
344
  return packageMap;
294
345
  }
295
346
  /**
@@ -311,6 +362,14 @@ var AnimusWebpackPlugin = class {
311
362
  getOptions() {
312
363
  return this.options;
313
364
  }
365
+ /** Expose external package directories for webpack loader allowlisting */
366
+ getExternalPackageDirs() {
367
+ return this.externalPackageDirs;
368
+ }
369
+ /** Expose external package source entries for webpack resolve alias */
370
+ getExternalSourceEntries() {
371
+ return this.externalSourceEntries;
372
+ }
314
373
  };
315
374
  //#endregion
316
375
  //#region src/with-animus.ts
@@ -360,6 +419,8 @@ function withAnimus(options) {
360
419
  compiler.hooks.normalModuleFactory.tap("AnimusVirtualResolve", (nmf) => {
361
420
  nmf.hooks.beforeResolve.tap("AnimusVirtualResolve", (resolveData) => {
362
421
  if (resolveData.request === "virtual:animus/system-props") resolveData.request = systemPropsPath;
422
+ const srcEntry = plugin.getExternalSourceEntries().get(resolveData.request);
423
+ if (srcEntry) resolveData.request = srcEntry;
363
424
  });
364
425
  });
365
426
  } });
@@ -368,8 +429,15 @@ function withAnimus(options) {
368
429
  config.module = config.module || {};
369
430
  config.module.rules = config.module.rules || [];
370
431
  config.module.rules.push({
371
- test: /\.(ts|tsx|js|jsx)$/,
372
- exclude: /node_modules/,
432
+ test: (filePath) => {
433
+ if (/\.[jt]sx?$/.test(filePath)) return true;
434
+ if (/\.mjs$/.test(filePath)) return plugin.getExternalPackageDirs().some((dir) => filePath.startsWith(dir + sep) || filePath === dir);
435
+ return false;
436
+ },
437
+ exclude: (filePath) => {
438
+ if (!filePath.includes("node_modules")) return false;
439
+ return !plugin.getExternalPackageDirs().some((dir) => filePath.startsWith(dir + sep) || filePath === dir);
440
+ },
373
441
  enforce: "pre",
374
442
  use: [{
375
443
  loader: actualLoaderPath,
package/dist/plugin.d.ts CHANGED
@@ -23,6 +23,8 @@ export declare class AnimusWebpackPlugin {
23
23
  private systemResolveScript;
24
24
  private fileCache;
25
25
  private lastCssHash;
26
+ private externalPackageDirs;
27
+ private externalSourceEntries;
26
28
  constructor(options: AnimusNextOptions);
27
29
  private initialized;
28
30
  apply(compiler: Compiler): void;
@@ -43,6 +45,10 @@ export declare class AnimusWebpackPlugin {
43
45
  }>;
44
46
  /** Expose options for the loader */
45
47
  getOptions(): AnimusNextOptions;
48
+ /** Expose external package directories for webpack loader allowlisting */
49
+ getExternalPackageDirs(): string[];
50
+ /** Expose external package source entries for webpack resolve alias */
51
+ getExternalSourceEntries(): Map<string, string>;
46
52
  }
47
53
  export {};
48
54
  //# sourceMappingURL=plugin.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/plugin.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,KAAK,QAAQ,GAAG;IACd,KAAK,EAAE;QACL,GAAG,EAAE;YACH,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;SACxE,CAAC;QACF,QAAQ,EAAE;YACR,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,QAAQ,KAAK,OAAO,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;SACxE,CAAC;KACH,CAAC;IACF,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAIF,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,OAAO,CAAoB;IACnC,OAAO,CAAC,OAAO,CAAuB;IAGtC,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,iBAAiB,CAAM;IAC/B,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,eAAe,CAAM;IAC7B,OAAO,CAAC,WAAW,CAAM;IACzB,OAAO,CAAC,kBAAkB,CAAuB;IACjD,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,OAAO,CAAC,UAAU,CAAM;IACxB,OAAO,CAAC,iBAAiB,CAAM;IAC/B,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,eAAe,CAAM;IAC7B,OAAO,CAAC,WAAW,CAAM;IACzB,OAAO,CAAC,kBAAkB,CAAuB;IACjD,OAAO,CAAC,SAAS,CAAM;IACvB,OAAO,CAAC,mBAAmB,CAAuB;IAGlD,OAAO,CAAC,SAAS,CAAuD;IACxE,OAAO,CAAC,WAAW,CAAuB;IAG1C,OAAO,CAAC,mBAAmB,CAAgB;IAG3C,OAAO,CAAC,qBAAqB,CAA6B;gBAE9C,OAAO,EAAE,iBAAiB;IAItC,OAAO,CAAC,WAAW,CAAS;IAE5B,KAAK,CAAC,QAAQ,EAAE,QAAQ,GAAG,IAAI;YA2CjB,iBAAiB;YAwDjB,eAAe;IAkM7B,OAAO,CAAC,UAAU;IAiIlB,OAAO,CAAC,iBAAiB;IAqBzB,OAAO,CAAC,aAAa;IAyCrB,OAAO,CAAC,qBAAqB;IAmD7B;;OAEG;IACH,WAAW,IAAI,IAAI;IASnB,iDAAiD;IACjD,YAAY,IAAI,GAAG,CAAC,MAAM,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAE,CAAC;IAI7D,oCAAoC;IACpC,UAAU,IAAI,iBAAiB;IAI/B,0EAA0E;IAC1E,sBAAsB,IAAI,MAAM,EAAE;IAIlC,uEAAuE;IACvE,wBAAwB,IAAI,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;CAGhD"}
@@ -6,8 +6,8 @@ type WebpackConfig = {
6
6
  };
7
7
  module?: {
8
8
  rules?: Array<{
9
- test?: RegExp;
10
- exclude?: RegExp;
9
+ test?: RegExp | ((path: string) => boolean);
10
+ exclude?: RegExp | ((path: string) => boolean);
11
11
  enforce?: string;
12
12
  use?: Array<{
13
13
  loader: string;
@@ -1 +1 @@
1
- {"version":3,"file":"with-animus.d.ts","sourceRoot":"","sources":["../src/with-animus.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,KAAK,aAAa,GAAG;IACnB,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;IACpB,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAChC,CAAC;IACF,MAAM,CAAC,EAAE;QACP,KAAK,CAAC,EAAE,KAAK,CAAC;YACZ,IAAI,CAAC,EAAE,MAAM,CAAC;YACd,OAAO,CAAC,EAAE,MAAM,CAAC;YACjB,OAAO,CAAC,EAAE,MAAM,CAAC;YACjB,GAAG,CAAC,EAAE,KAAK,CAAC;gBAAE,MAAM,EAAE,MAAM,CAAC;gBAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;aAAE,CAAC,CAAC;SACpE,CAAC,CAAC;KACJ,CAAC;CACH,CAAC;AAEF,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAC1C,OAAO,CAAC,EAAE,CACR,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,aAAa,CAAC;CACpB,CAAC;AAIF;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,iBAAiB,GACzB,CAAC,UAAU,EAAE,UAAU,KAAK,UAAU,CAkIxC"}
1
+ {"version":3,"file":"with-animus.d.ts","sourceRoot":"","sources":["../src/with-animus.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAC;AAEjD,KAAK,aAAa,GAAG;IACnB,OAAO,CAAC,EAAE,OAAO,EAAE,CAAC;IACpB,OAAO,CAAC,EAAE;QACR,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;KAChC,CAAC;IACF,MAAM,CAAC,EAAE;QACP,KAAK,CAAC,EAAE,KAAK,CAAC;YACZ,IAAI,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;YAC5C,OAAO,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,CAAC;YAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;YACjB,GAAG,CAAC,EAAE,KAAK,CAAC;gBAAE,MAAM,EAAE,MAAM,CAAC;gBAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;aAAE,CAAC,CAAC;SACpE,CAAC,CAAC;KACJ,CAAC;CACH,CAAC;AAEF,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAC1C,OAAO,CAAC,EAAE,CACR,MAAM,EAAE,aAAa,EACrB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC7B,aAAa,CAAC;CACpB,CAAC;AAIF;;;;;;;;GAQG;AACH,wBAAgB,UAAU,CACxB,OAAO,EAAE,iBAAiB,GACzB,CAAC,UAAU,EAAE,UAAU,KAAK,UAAU,CA8JxC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@animus-ui/next-plugin",
3
- "version": "0.1.0-next.30",
3
+ "version": "0.1.0-next.31",
4
4
  "description": "Animus static CSS extraction for Next.js (webpack)",
5
5
  "author": "codecaaron <airrobb@gmail.com>",
6
6
  "license": "MIT",
@@ -38,6 +38,6 @@
38
38
  "webpack": ">=5.0.0"
39
39
  },
40
40
  "dependencies": {
41
- "@animus-ui/extract": "0.1.0-next.30"
41
+ "@animus-ui/extract": "0.1.0-next.31"
42
42
  }
43
43
  }