@jesscss/plugin-node-modules 2.0.0-alpha.6 → 2.0.0-alpha.8

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/README.md CHANGED
@@ -1,74 +1,35 @@
1
1
  # @jesscss/plugin-node-modules
2
2
 
3
- Jess plugin for resolving and loading npm packages from `node_modules`.
4
-
5
- ## Overview
6
-
7
- This plugin provides npm/node_modules resolution and loading capabilities for all Jess language plugins. It uses Node's module resolution algorithm (`require.resolve`) to find and load npm packages.
8
-
9
- ## Usage
10
-
11
- ```typescript
12
- import { Compiler } from '@jesscss/jess';
13
- import nodeModulesPlugin from '@jesscss/plugin-node-modules';
14
-
15
- const compiler = new Compiler({
16
- compile: {
17
- plugins: [
18
- nodeModulesPlugin(),
19
- // ... other plugins
20
- ]
21
- }
22
- });
23
- ```
24
-
25
- ## API
26
-
27
- ### `resolvePackage(packageName: string): string | null`
28
-
29
- Resolve an npm package name to its absolute path.
30
-
31
- ```typescript
32
- const plugin = new NodeModulesPlugin();
33
- const path = plugin.resolvePackage('less-plugin-clean-css');
34
- // Returns: '/path/to/node_modules/less-plugin-clean-css/index.js' or null
35
- ```
36
-
37
- ### `loadPackage(packageName: string): Promise<Record<string, any> | null>`
38
-
39
- Load an npm package module.
40
-
41
- ```typescript
42
- const plugin = new NodeModulesPlugin();
43
- const module = await plugin.loadPackage('less-plugin-clean-css');
44
- // Returns: the module exports, or null if not found
45
- ```
46
-
47
- ### `tryResolvePackages(packageNames: string[]): Promise<{ name: string; module: Record<string, any> } | null>`
48
-
49
- Try to resolve a package name with multiple possible names. Returns the first successfully resolved package.
50
-
51
- ```typescript
52
- const plugin = new NodeModulesPlugin();
53
- const result = await plugin.tryResolvePackages([
54
- 'clean-css',
55
- 'less-plugin-clean-css'
56
- ]);
57
- // Returns: { name: 'less-plugin-clean-css', module: {...} } or null
58
- ```
59
-
60
- ## Integration with Other Plugins
61
-
62
- Other plugins (like `@jesscss/plugin-less-compat`) can use this plugin to resolve npm packages:
63
-
64
- ```typescript
65
- // In jess-plugin-less-compat
66
- const nodeModulesPlugin = plugins.find(p => p.name === 'node-modules');
67
- if (nodeModulesPlugin instanceof NodeModulesPlugin) {
68
- const module = await nodeModulesPlugin.loadPackage('less-plugin-clean-css');
69
- }
70
- ```
71
-
72
- ## Options
73
-
74
- - `enabled` (boolean, default: `true`): Whether to enable auto-resolution of npm packages.
3
+ **Import resolver that loads npm packages from `node_modules` — a seed of the
4
+ JavaScript-execution / CSS-in-JS story.**
5
+
6
+ This plugin gives Jess's language plugins a way to resolve and load npm packages
7
+ by name, using Node's module resolution (`require.resolve` /
8
+ `createRequire`). Other plugins use it to pull in packages referenced from a
9
+ stylesheet — for example [`@jesscss/plugin-less-compat`](../jess-plugin-less-compat)
10
+ resolving a Less `@plugin "package-name"` off `node_modules`.
11
+
12
+ ## Why it exists the convergence angle
13
+
14
+ One of the four tools [Jess](https://github.com/jesscss/jess) aims to converge is
15
+ **CSS-in-JS**: running real JavaScript inside your stylesheets (`@use` /
16
+ `@plugin`) so styles can be dynamic without leaving CSS files. Reaching npm
17
+ packages is a building block of that story. Paired with
18
+ [`@jesscss/plugin-js`](../jess-plugin-js) (which executes the modules), it lets a
19
+ stylesheet pull logic and data from the JS ecosystem.
20
+
21
+ That convergence is **roadmap — being proven through the alpha, not claimed as
22
+ done.** What ships here today is just the resolver seam; don't read it as a
23
+ finished CSS-in-JS system.
24
+
25
+ ## Status
26
+
27
+ **Alpha.** Part of Jess, the ground-up rewrite of Less.js (Jess *is* Less.js
28
+ v5). The programmatic plugin/compiler API is **not yet stabilized** — the `jess`
29
+ / `lessc` CLIs are the public surface for the alpha. Watch the
30
+ [docs site](https://jesscss.github.io/) for the API once it settles.
31
+
32
+ - Project overview & positioning: <https://github.com/jesscss/jess#readme>
33
+ - Docs: <https://jesscss.github.io/> (currently pre-alpha content)
34
+ - Issues: <https://github.com/jesscss/jess/issues>
35
+ - License: MIT
package/lib/index.js CHANGED
@@ -107,5 +107,3 @@ const nodeModulesPlugin = ((opts) => {
107
107
  });
108
108
  //#endregion
109
109
  export { NodeModulesPlugin, nodeModulesPlugin as default };
110
-
111
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,13 +1,12 @@
1
1
  {
2
2
  "name": "@jesscss/plugin-node-modules",
3
- "version": "2.0.0-alpha.6",
3
+ "version": "2.0.0-alpha.8",
4
4
  "description": "Jess plugin for resolving and loading npm packages from node_modules",
5
5
  "main": "lib/index.cjs",
6
6
  "types": "lib/index.d.ts",
7
7
  "exports": {
8
8
  ".": {
9
9
  "types": "./lib/index.d.ts",
10
- "source": "./src/index.ts",
11
10
  "import": "./lib/index.js",
12
11
  "require": "./lib/index.cjs"
13
12
  },
@@ -17,7 +16,7 @@
17
16
  "lib"
18
17
  ],
19
18
  "dependencies": {
20
- "@jesscss/core": "2.0.0-alpha.6"
19
+ "@jesscss/core": "2.0.0-alpha.8"
21
20
  },
22
21
  "devDependencies": {
23
22
  "@types/node": "^20.0.0",
@@ -32,7 +31,7 @@
32
31
  "module": "lib/index.js",
33
32
  "scripts": {
34
33
  "build": "pnpm compile",
35
- "compile": "tsdown --tsconfig tsconfig.build.json && tsc -p tsconfig.build.json --emitDeclarationOnly",
34
+ "compile": "tsdown --tsconfig tsconfig.build.json --no-dts && tsc -p tsconfig.build.json --emitDeclarationOnly",
36
35
  "dev": "tsdown --tsconfig tsconfig.build.json --watch",
37
36
  "lint:fix": "eslint --fix '**/*.{js,ts}'",
38
37
  "lint": "eslint '**/*.{js,ts}'"
package/lib/index.d.cts DELETED
@@ -1,64 +0,0 @@
1
- import { AbstractPlugin } from "@jesscss/core";
2
-
3
- //#region src/index.d.ts
4
- interface NodeModulesPluginOptions {
5
- /**
6
- * Whether to enable auto-resolution of npm packages.
7
- * Default: true
8
- */
9
- enabled?: boolean;
10
- }
11
- /**
12
- * Plugin that provides npm/node_modules resolution and loading capabilities.
13
- *
14
- * This plugin implements the `import()` method to resolve and load npm packages
15
- * using Node's module resolution algorithm (require.resolve).
16
- *
17
- * It can be used by other plugins (like jess-plugin-less-compat) to load
18
- * npm packages when processing directives like `@plugin "package-name"`.
19
- */
20
- declare class NodeModulesPlugin extends AbstractPlugin {
21
- opts: NodeModulesPluginOptions;
22
- name: string;
23
- private _require;
24
- constructor(opts?: NodeModulesPluginOptions);
25
- /**
26
- * Resolve an npm package name to its absolute path.
27
- * Uses Node's module resolution algorithm (same as require.resolve).
28
- *
29
- * @param packageName - The npm package name (e.g., "less-plugin-clean-css")
30
- * @returns The absolute path to the package, or null if not found
31
- */
32
- resolvePackage(packageName: string): string | null;
33
- /**
34
- * Load an npm package module.
35
- *
36
- * @param packageName - The npm package name (e.g., "less-plugin-clean-css")
37
- * @returns The loaded module, or null if not found
38
- */
39
- loadPackage(packageName: string): Promise<Record<string, any> | null>;
40
- /**
41
- * Try to resolve a package name with multiple possible names.
42
- * Useful for plugins that want to try different variations
43
- * (e.g., "clean-css" and "less-plugin-clean-css").
44
- *
45
- * @param packageNames - Array of package names to try in order
46
- * @returns The first successfully resolved package, or null if none found
47
- */
48
- tryResolvePackages(packageNames: string[]): Promise<{
49
- name: string;
50
- module: Record<string, any>;
51
- } | null>;
52
- /**
53
- * Import method for loading JavaScript modules from npm.
54
- * This is called by the context when importing modules.
55
- *
56
- * @param absoluteFilePath - The absolute path to the module
57
- * @returns The loaded module, or throws if this plugin can't handle it
58
- */
59
- import(absoluteFilePath: string): Promise<Record<string, any>>;
60
- }
61
- declare const nodeModulesPlugin: (opts?: NodeModulesPluginOptions) => NodeModulesPlugin;
62
- //#endregion
63
- export { NodeModulesPlugin, type NodeModulesPluginOptions, nodeModulesPlugin as default };
64
- //# sourceMappingURL=index.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;UASU,wBAAA;;AALa;;;EAUrB,OAAA;AAAA;;;;;;;;;;cAcW,iBAAA,SAA0B,cAAA;EAKlB,IAAA,EAAM,wBAAA;EAJzB,IAAA;EAAA,QAEQ,QAAA;cAEW,IAAA,GAAM,wBAAA;EAAN;;;;;;;EAqCnB,cAAA,CAAe,WAAA;EAAA;;;;;;EA0BT,WAAA,CAAY,WAAA,WAAsB,OAAA,CAAQ,MAAA;EAyBE;;;;;;;;EAA5C,kBAAA,CAAmB,YAAA,aAAyB,OAAA;IAAU,IAAA;IAAc,MAAA,EAAQ,MAAA;EAAA;;;;;;;;EAiB5E,MAAA,CAAO,gBAAA,WAA2B,OAAA,CAAQ,MAAA;AAAA;AAAA,cAsB5C,iBAAA,GAAiB,IAAA,GAAY,wBAAA,KAAwB,iBAAA"}
package/lib/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["import {\n type Plugin,\n type PluginInterface,\n AbstractPlugin\n} from '@jesscss/core';\nimport { createRequire } from 'node:module';\nimport { fileURLToPath } from 'node:url';\nimport * as path from 'node:path';\n\ninterface NodeModulesPluginOptions {\n /**\n * Whether to enable auto-resolution of npm packages.\n * Default: true\n */\n enabled?: boolean;\n}\n\nexport type { NodeModulesPluginOptions };\n\n/**\n * Plugin that provides npm/node_modules resolution and loading capabilities.\n *\n * This plugin implements the `import()` method to resolve and load npm packages\n * using Node's module resolution algorithm (require.resolve).\n *\n * It can be used by other plugins (like jess-plugin-less-compat) to load\n * npm packages when processing directives like `@plugin \"package-name\"`.\n */\nexport class NodeModulesPlugin extends AbstractPlugin {\n name = 'node-modules';\n\n private _require: NodeRequire;\n\n constructor(public opts: NodeModulesPluginOptions = {}) {\n super();\n\n // Create a require function that can resolve modules\n // Use createRequire to get a require function in ES module contexts\n try {\n // Try to use the current file's directory as the base for resolution\n let currentDir: string;\n if (typeof __filename !== 'undefined') {\n currentDir = path.dirname(__filename);\n } else {\n // In ES module contexts, try to use import.meta.url\n // This will only work if the module system supports it\n try {\n const url = import.meta.url;\n currentDir = path.dirname(fileURLToPath(url));\n } catch {\n // Fallback to process.cwd()\n currentDir = process.cwd();\n }\n }\n this._require = createRequire(currentDir + '/');\n } catch {\n // Fallback to global require if available\n this._require = typeof require !== 'undefined'\n ? require\n : createRequire(process.cwd() + '/');\n }\n }\n\n /**\n * Resolve an npm package name to its absolute path.\n * Uses Node's module resolution algorithm (same as require.resolve).\n *\n * @param packageName - The npm package name (e.g., \"less-plugin-clean-css\")\n * @returns The absolute path to the package, or null if not found\n */\n resolvePackage(packageName: string): string | null {\n if (this.opts.enabled === false) {\n return null;\n }\n\n try {\n // Use require.resolve to find the package\n // This will search node_modules using Node's resolution algorithm\n const resolved = this._require.resolve(packageName);\n return resolved;\n } catch (e: any) {\n // MODULE_NOT_FOUND is expected when package doesn't exist\n if (e.code === 'MODULE_NOT_FOUND') {\n return null;\n }\n // Re-throw other errors\n throw e;\n }\n }\n\n /**\n * Load an npm package module.\n *\n * @param packageName - The npm package name (e.g., \"less-plugin-clean-css\")\n * @returns The loaded module, or null if not found\n */\n async loadPackage(packageName: string): Promise<Record<string, any> | null> {\n const resolvedPath = this.resolvePackage(packageName);\n if (!resolvedPath) {\n return null;\n }\n\n try {\n // Load the module using require\n\n const module = this._require(resolvedPath) as Record<string, unknown>;\n return module || null;\n } catch {\n // If loading fails, return null\n return null;\n }\n }\n\n /**\n * Try to resolve a package name with multiple possible names.\n * Useful for plugins that want to try different variations\n * (e.g., \"clean-css\" and \"less-plugin-clean-css\").\n *\n * @param packageNames - Array of package names to try in order\n * @returns The first successfully resolved package, or null if none found\n */\n async tryResolvePackages(packageNames: string[]): Promise<{ name: string; module: Record<string, any> } | null> {\n for (const name of packageNames) {\n const module = await this.loadPackage(name);\n if (module !== null) {\n return { name, module };\n }\n }\n return null;\n }\n\n /**\n * Import method for loading JavaScript modules from npm.\n * This is called by the context when importing modules.\n *\n * @param absoluteFilePath - The absolute path to the module\n * @returns The loaded module, or throws if this plugin can't handle it\n */\n async import(absoluteFilePath: string): Promise<Record<string, any>> {\n if (this.opts.enabled === false) {\n throw new Error(`Plugin \"${this.name}\" cannot import \"${absoluteFilePath}\" (disabled)`);\n }\n\n // Check if this looks like a node_modules path\n // We can't directly resolve from absolute paths, but we can try to require it\n if (absoluteFilePath.includes('node_modules')) {\n try {\n const module = this._require(absoluteFilePath) as Record<string, unknown>;\n return module;\n } catch (e: unknown) {\n const message = e instanceof Error ? e.message : String(e);\n throw new Error(`Failed to import \"${absoluteFilePath}\": ${message}`);\n }\n }\n\n // For non-node_modules paths, throw to let other plugins handle it\n throw new Error(`Plugin \"${this.name}\" cannot import \"${absoluteFilePath}\" (not a node_modules path)`);\n }\n}\n\nconst nodeModulesPlugin = ((opts?: NodeModulesPluginOptions) => {\n return new NodeModulesPlugin(opts);\n}) satisfies Plugin;\n\nexport default nodeModulesPlugin;\n"],"mappings":";;;;;;;;;;;;;;;;;AA4BA,IAAa,oBAAb,cAAuC,eAAe;CACpD,OAAO;CAEP;CAEA,YAAY,OAAwC,EAAE,EAAE;AACtD,SAAO;AADU,OAAA,OAAA;AAKjB,MAAI;GAEF,IAAI;AACJ,OAAI,OAAO,eAAe,YACxB,cAAa,KAAK,QAAQ,WAAW;OAIrC,KAAI;IACF,MAAM,MAAM,OAAO,KAAK;AACxB,iBAAa,KAAK,QAAQ,cAAc,IAAI,CAAC;WACvC;AAEN,iBAAa,QAAQ,KAAK;;AAG9B,QAAK,WAAW,cAAc,aAAa,IAAI;UACzC;AAEN,QAAK,WAAW,OAAA,cAAmB,cAAA,YAE/B,cAAc,QAAQ,KAAK,GAAG,IAAI;;;;;;;;;;CAW1C,eAAe,aAAoC;AACjD,MAAI,KAAK,KAAK,YAAY,MACxB,QAAO;AAGT,MAAI;AAIF,UADiB,KAAK,SAAS,QAAQ,YAAY;WAE5C,GAAQ;AAEf,OAAI,EAAE,SAAS,mBACb,QAAO;AAGT,SAAM;;;;;;;;;CAUV,MAAM,YAAY,aAA0D;EAC1E,MAAM,eAAe,KAAK,eAAe,YAAY;AACrD,MAAI,CAAC,aACH,QAAO;AAGT,MAAI;AAIF,UADe,KAAK,SAAS,aAAa,IACzB;UACX;AAEN,UAAO;;;;;;;;;;;CAYX,MAAM,mBAAmB,cAAuF;AAC9G,OAAK,MAAM,QAAQ,cAAc;GAC/B,MAAM,SAAS,MAAM,KAAK,YAAY,KAAK;AAC3C,OAAI,WAAW,KACb,QAAO;IAAE;IAAM;IAAQ;;AAG3B,SAAO;;;;;;;;;CAUT,MAAM,OAAO,kBAAwD;AACnE,MAAI,KAAK,KAAK,YAAY,MACxB,OAAM,IAAI,MAAM,WAAW,KAAK,KAAK,mBAAmB,iBAAiB,cAAc;AAKzF,MAAI,iBAAiB,SAAS,eAAe,CAC3C,KAAI;AAEF,UADe,KAAK,SAAS,iBAAiB;WAEvC,GAAY;GACnB,MAAM,UAAU,aAAa,QAAQ,EAAE,UAAU,OAAO,EAAE;AAC1D,SAAM,IAAI,MAAM,qBAAqB,iBAAiB,KAAK,UAAU;;AAKzE,QAAM,IAAI,MAAM,WAAW,KAAK,KAAK,mBAAmB,iBAAiB,6BAA6B;;;AAI1G,MAAM,sBAAsB,SAAoC;AAC9D,QAAO,IAAI,kBAAkB,KAAK"}