unplugin-solid-labels 0.17.1 → 1.0.0

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
@@ -27,12 +27,6 @@ import solidLabels from 'unplugin-solid-labels';
27
27
  solidLabels.vite({
28
28
  dev: true, // defaults to false
29
29
  disabled: {
30
- labels: {
31
- signal: true,
32
- },
33
- pragma: {
34
- '@signal': true,
35
- },
36
30
  ctf: {
37
31
  $signal: true,
38
32
  },
@@ -44,6 +38,49 @@ solidLabels.vite({
44
38
  });
45
39
  ```
46
40
 
41
+ ### Bun
42
+
43
+ `solidLabels.bun(options)` needs Bun 1.2.22 or later.
44
+
45
+ Bun uses the first `onLoad` that returns contents for a file. Two separate Bun plugins, `solidLabels.bun()` and a Solid JSX plugin, never chain, in either order. The second one never receives the output of the first.
46
+
47
+ Plugins returned from one unplugin factory run their `transform` hooks in order inside a single `onLoad`, and their source maps are combined. Put solid-labels and the JSX step in one factory:
48
+
49
+ ```ts
50
+ import { transformAsync } from '@solidjs/compiler';
51
+ import { createUnplugin } from 'unplugin';
52
+ import type { UnpluginOptions } from 'unplugin';
53
+ import solidLabels from 'unplugin-solid-labels';
54
+
55
+ const solidJsx: UnpluginOptions = {
56
+ name: 'solid-jsx',
57
+ transform: {
58
+ filter: { id: /\/src\/.*\.[jt]sx$/ },
59
+ async handler(code, id) {
60
+ const result = await transformAsync(code, { filename: id, generate: 'dom', sourceMap: true });
61
+ return { code: result.code, map: result.map };
62
+ },
63
+ },
64
+ };
65
+
66
+ const solidBun = createUnplugin((_options: undefined, meta) => [
67
+ solidLabels.raw({ filter: { include: '**/src/**/*.{ts,tsx}' } }, meta),
68
+ solidJsx,
69
+ ]).bun;
70
+
71
+ await Bun.build({
72
+ entrypoints: ['./src/main.tsx'],
73
+ outdir: './dist',
74
+ sourcemap: 'external',
75
+ plugins: [solidBun()],
76
+ });
77
+ ```
78
+
79
+ - Solid 2.0 has no maintained Bun plugin. `@solidjs/compiler` is the compiler that `@solidjs/vite-plugin` uses.
80
+ - Bun plugins such as `bun-plugin-solid` and `@angius/bun-plugin-solid` use `babel-preset-solid` 1.x, which emits Solid 1 output.
81
+
82
+ See [`examples/bun`](https://github.com/lxsmnsyc/solid-labels/tree/main/examples/bun) for a full build and a check that runs the bundle.
83
+
47
84
  ## Sponsors
48
85
 
49
86
  ![Sponsors](https://github.com/lxsmnsyc/sponsors/blob/main/sponsors.svg?raw=true)
package/dist/index.d.mts CHANGED
@@ -1,7 +1,6 @@
1
+ import { Options } from "solid-labels/compiler";
1
2
  import { FilterPattern } from "@rollup/pluginutils";
2
- import { Options } from "solid-labels/babel";
3
- //#region src/index.d.ts
4
- export interface SolidLabelsPluginFilter {
3
+ interface SolidLabelsPluginFilter {
5
4
  include?: FilterPattern;
6
5
  exclude?: FilterPattern;
7
6
  }
@@ -9,6 +8,5 @@ export interface SolidLabelsPluginOptions extends Options {
9
8
  filter?: SolidLabelsPluginFilter;
10
9
  }
11
10
  declare const solidLabelsPlugin: import("unplugin").UnpluginInstance<SolidLabelsPluginOptions | undefined, boolean>;
12
- //#endregion
13
- export { solidLabelsPlugin as default };
11
+ export { type SolidLabelsPluginFilter, solidLabelsPlugin as default };
14
12
  //# sourceMappingURL=index.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.mts","names":[],"sources":["../src/index.ts"],"mappings":";;;iBAUiB;EACf,UAAU;EACV,UAAU;;iBAGK,iCAAiC;EAChD,SAAS;;cA+BL,sCAAiB,iBAAA"}
1
+ {"version":3,"file":"index.d.mts","names":[],"sources":["../src/filter.ts","../src/index.ts"],"mappings":";;UAGiB;EACf,UAAU;EACV,UAAU;;iBCKK,iCAAiC;EAChD,SAAS;;cA0BL,sCAAiB,iBAAA"}
package/dist/index.mjs CHANGED
@@ -1,9 +1,18 @@
1
- import * as babel from "@babel/core";
2
- import { createFilter } from "@rollup/pluginutils";
3
- import path from "node:path";
4
- import solidLabelsBabel from "solid-labels/babel";
1
+ import { compile } from "solid-labels/compiler";
5
2
  import { createUnplugin } from "unplugin";
6
- //#region src/index.ts
3
+ import { createFilter } from "@rollup/pluginutils";
4
+ // src/filter.ts
5
+ const DEFAULT_INCLUDE = "src/**/*.{jsx,tsx,ts,js,mjs,cjs}";
6
+ const DEFAULT_EXCLUDE = "node_modules/**/*.{jsx,tsx,ts,js,mjs,cjs}";
7
+ function removeQuery(id) {
8
+ const index = id.indexOf("?");
9
+ return index === -1 ? id : id.slice(0, index);
10
+ }
11
+ function createIdFilter(options) {
12
+ const filter = createFilter(options?.include ?? DEFAULT_INCLUDE, options?.exclude ?? DEFAULT_EXCLUDE);
13
+ return (id) => filter(removeQuery(id));
14
+ }
15
+ // src/index.ts
7
16
  function repushPlugin(plugins, pluginName, pluginNames) {
8
17
  const namesSet = new Set(pluginNames);
9
18
  let baseIndex = -1;
@@ -22,36 +31,23 @@ function repushPlugin(plugins, pluginName, pluginNames) {
22
31
  plugins.splice(baseIndex, 0, targetPlugin);
23
32
  }
24
33
  }
25
- const DEFAULT_INCLUDE = "src/**/*.{jsx,tsx,ts,js,mjs,cjs}";
26
- const DEFAULT_EXCLUDE = "node_modules/**/*.{jsx,tsx,ts,js,mjs,cjs}";
27
- const FILE_FILTER = /\.[mc]?tsx?$/i;
28
34
  const solidLabelsPlugin = createUnplugin((rawOptions) => {
29
35
  const options = rawOptions ?? {};
30
- const filter = createFilter(options.filter?.include ?? DEFAULT_INCLUDE, options.filter?.exclude ?? DEFAULT_EXCLUDE);
36
+ const filter = createIdFilter(options.filter);
31
37
  let env;
32
38
  return {
33
39
  name: "solid-labels",
34
40
  transformInclude(id) {
35
41
  return filter(id);
36
42
  },
37
- async transform(code, id) {
38
- const plugins = ["jsx"];
39
- if (FILE_FILTER.test(id)) plugins.push("typescript");
40
- const result = await babel.transformAsync(code, {
41
- plugins: [[solidLabelsBabel, {
42
- disabled: options.disabled,
43
- dev: env === "development" || options.dev
44
- }]],
45
- parserOpts: { plugins },
46
- filename: path.basename(id),
47
- ast: false,
48
- sourceMaps: true,
49
- configFile: false,
50
- babelrc: false,
51
- sourceFileName: id
43
+ transform(code, id) {
44
+ const result = compile(id, code, {
45
+ disabled: options.disabled,
46
+ dev: env === "development" || options.dev
52
47
  });
53
- if (result) return {
54
- code: result.code ?? "",
48
+ if (result === null) return null;
49
+ return {
50
+ code: result.code,
55
51
  map: result.map
56
52
  };
57
53
  },
@@ -68,7 +64,6 @@ const solidLabelsPlugin = createUnplugin((rawOptions) => {
68
64
  }
69
65
  };
70
66
  });
71
- //#endregion
72
67
  export { solidLabelsPlugin as default };
73
68
 
74
69
  //# sourceMappingURL=index.mjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["import * as babel from '@babel/core';\nimport type { FilterPattern } from '@rollup/pluginutils';\nimport { createFilter } from '@rollup/pluginutils';\nimport path from 'node:path';\nimport type { Options } from 'solid-labels/babel';\nimport solidLabelsBabel from 'solid-labels/babel';\nimport type { TransformResult } from 'unplugin';\nimport { createUnplugin } from 'unplugin';\nimport type { Plugin } from 'vite';\n\nexport interface SolidLabelsPluginFilter {\n include?: FilterPattern;\n exclude?: FilterPattern;\n}\n\nexport interface SolidLabelsPluginOptions extends Options {\n filter?: SolidLabelsPluginFilter;\n}\n\n// From: https://github.com/bluwy/whyframe/blob/master/packages/jsx/src/index.js#L27-L37\nfunction repushPlugin(plugins: Plugin[], pluginName: string, pluginNames: string[]): void {\n const namesSet = new Set(pluginNames);\n\n let baseIndex = -1;\n let targetIndex = -1;\n let targetPlugin: Plugin | undefined;\n for (let i = 0, len = plugins.length; i < len; i += 1) {\n const current = plugins[i];\n if (namesSet.has(current.name) && baseIndex === -1) {\n baseIndex = i;\n }\n if (current.name === pluginName) {\n targetIndex = i;\n targetPlugin = current;\n }\n }\n if (targetPlugin && baseIndex !== -1 && targetIndex !== -1 && baseIndex < targetIndex) {\n plugins.splice(targetIndex, 1);\n plugins.splice(baseIndex, 0, targetPlugin);\n }\n}\n\nconst DEFAULT_INCLUDE = 'src/**/*.{jsx,tsx,ts,js,mjs,cjs}';\nconst DEFAULT_EXCLUDE = 'node_modules/**/*.{jsx,tsx,ts,js,mjs,cjs}';\n\nconst FILE_FILTER = /\\.[mc]?tsx?$/i;\n\nconst solidLabelsPlugin = createUnplugin((rawOptions?: SolidLabelsPluginOptions) => {\n const options = rawOptions ?? {};\n const filter = createFilter(\n options.filter?.include ?? DEFAULT_INCLUDE,\n options.filter?.exclude ?? DEFAULT_EXCLUDE,\n );\n\n let env: string;\n\n return {\n name: 'solid-labels',\n transformInclude(id): boolean {\n return filter(id);\n },\n async transform(code, id): Promise<TransformResult> {\n const plugins: NonNullable<NonNullable<babel.TransformOptions['parserOpts']>['plugins']> = [\n 'jsx',\n ];\n if (FILE_FILTER.test(id)) {\n plugins.push('typescript');\n }\n const result = await babel.transformAsync(code, {\n plugins: [\n [\n solidLabelsBabel,\n {\n disabled: options.disabled,\n dev: env === 'development' || options.dev,\n },\n ],\n ],\n parserOpts: {\n plugins,\n },\n filename: path.basename(id),\n ast: false,\n sourceMaps: true,\n configFile: false,\n babelrc: false,\n sourceFileName: id,\n });\n\n if (result) {\n return {\n code: result.code ?? '',\n map: result.map,\n };\n }\n return undefined;\n },\n vite: {\n enforce: 'pre',\n configResolved(config): void {\n env = config.mode === 'production' ? 'production' : 'development';\n\n // run our plugin before the following plugins:\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n repushPlugin(config.plugins as Plugin[], 'solid-labels', [\n // https://github.com/withastro/astro/blob/main/packages/astro/src/vite-plugin-jsx/index.ts#L173\n 'astro:jsx',\n // https://github.com/solidjs/vite-plugin-solid/blob/master/src/index.ts#L305\n 'solid',\n // https://github.com/solidjs/solid-start/blob/main/packages/start/vite/plugin.js#L118\n 'solid-start-file-system-router',\n ]);\n },\n },\n };\n});\n\nexport default solidLabelsPlugin;\n"],"mappings":";;;;;;AAoBA,SAAS,aAAa,SAAmB,YAAoB,aAA6B;CACxF,MAAM,WAAW,IAAI,IAAI,WAAW;CAEpC,IAAI,YAAY;CAChB,IAAI,cAAc;CAClB,IAAI;CACJ,KAAK,IAAI,IAAI,GAAG,MAAM,QAAQ,QAAQ,IAAI,KAAK,KAAK,GAAG;EACrD,MAAM,UAAU,QAAQ;EACxB,IAAI,SAAS,IAAI,QAAQ,IAAI,KAAK,cAAc,IAC9C,YAAY;EAEd,IAAI,QAAQ,SAAS,YAAY;GAC/B,cAAc;GACd,eAAe;EACjB;CACF;CACA,IAAI,gBAAgB,cAAc,MAAM,gBAAgB,MAAM,YAAY,aAAa;EACrF,QAAQ,OAAO,aAAa,CAAC;EAC7B,QAAQ,OAAO,WAAW,GAAG,YAAY;CAC3C;AACF;AAEA,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AAExB,MAAM,cAAc;AAEpB,MAAM,oBAAoB,gBAAgB,eAA0C;CAClF,MAAM,UAAU,cAAc,CAAC;CAC/B,MAAM,SAAS,aACb,QAAQ,QAAQ,WAAW,iBAC3B,QAAQ,QAAQ,WAAW,eAC7B;CAEA,IAAI;CAEJ,OAAO;EACL,MAAM;EACN,iBAAiB,IAAa;GAC5B,OAAO,OAAO,EAAE;EAClB;EACA,MAAM,UAAU,MAAM,IAA8B;GAClD,MAAM,UAAqF,CACzF,KACF;GACA,IAAI,YAAY,KAAK,EAAE,GACrB,QAAQ,KAAK,YAAY;GAE3B,MAAM,SAAS,MAAM,MAAM,eAAe,MAAM;IAC9C,SAAS,CACP,CACE,kBACA;KACE,UAAU,QAAQ;KAClB,KAAK,QAAQ,iBAAiB,QAAQ;IACxC,CACF,CACF;IACA,YAAY,EACV,QACF;IACA,UAAU,KAAK,SAAS,EAAE;IAC1B,KAAK;IACL,YAAY;IACZ,YAAY;IACZ,SAAS;IACT,gBAAgB;GAClB,CAAC;GAED,IAAI,QACF,OAAO;IACL,MAAM,OAAO,QAAQ;IACrB,KAAK,OAAO;GACd;EAGJ;EACA,MAAM;GACJ,SAAS;GACT,eAAe,QAAc;IAC3B,MAAM,OAAO,SAAS,eAAe,eAAe;IAIpD,aAAa,OAAO,SAAqB,gBAAgB;KAEvD;KAEA;KAEA;IACF,CAAC;GACH;EACF;CACF;AACF,CAAC"}
1
+ {"version":3,"file":"index.mjs","names":[],"sources":["../src/filter.ts","../src/index.ts"],"sourcesContent":["import type { FilterPattern } from '@rollup/pluginutils';\nimport { createFilter } from '@rollup/pluginutils';\n\nexport interface SolidLabelsPluginFilter {\n include?: FilterPattern;\n exclude?: FilterPattern;\n}\n\nconst DEFAULT_INCLUDE = 'src/**/*.{jsx,tsx,ts,js,mjs,cjs}';\nconst DEFAULT_EXCLUDE = 'node_modules/**/*.{jsx,tsx,ts,js,mjs,cjs}';\n\nfunction removeQuery(id: string): string {\n const index = id.indexOf('?');\n return index === -1 ? id : id.slice(0, index);\n}\n\nexport function createIdFilter(options?: SolidLabelsPluginFilter): (id: string) => boolean {\n const filter = createFilter(\n options?.include ?? DEFAULT_INCLUDE,\n options?.exclude ?? DEFAULT_EXCLUDE,\n );\n return (id) =>\n // Bundlers can add a query to a module id, as SolidStart does with\n // `?pick=` for route files. Match the file path without it.\n filter(removeQuery(id));\n}\n","import type { Options } from 'solid-labels/compiler';\nimport { compile } from 'solid-labels/compiler';\nimport type { TransformResult } from 'unplugin';\nimport { createUnplugin } from 'unplugin';\nimport type { Plugin } from 'vite';\nimport type { SolidLabelsPluginFilter } from './filter';\nimport { createIdFilter } from './filter';\n\nexport type { SolidLabelsPluginFilter };\n\nexport interface SolidLabelsPluginOptions extends Options {\n filter?: SolidLabelsPluginFilter;\n}\n\n// From: https://github.com/bluwy/whyframe/blob/master/packages/jsx/src/index.js#L27-L37\nfunction repushPlugin(plugins: Plugin[], pluginName: string, pluginNames: string[]): void {\n const namesSet = new Set(pluginNames);\n\n let baseIndex = -1;\n let targetIndex = -1;\n let targetPlugin: Plugin | undefined;\n for (let i = 0, len = plugins.length; i < len; i += 1) {\n const current = plugins[i];\n if (namesSet.has(current.name) && baseIndex === -1) {\n baseIndex = i;\n }\n if (current.name === pluginName) {\n targetIndex = i;\n targetPlugin = current;\n }\n }\n if (targetPlugin && baseIndex !== -1 && targetIndex !== -1 && baseIndex < targetIndex) {\n plugins.splice(targetIndex, 1);\n plugins.splice(baseIndex, 0, targetPlugin);\n }\n}\n\nconst solidLabelsPlugin = createUnplugin((rawOptions?: SolidLabelsPluginOptions) => {\n const options = rawOptions ?? {};\n const filter = createIdFilter(options.filter);\n\n let env: string;\n\n return {\n name: 'solid-labels',\n transformInclude(id): boolean {\n return filter(id);\n },\n transform(code, id): TransformResult | null {\n const result = compile(id, code, {\n disabled: options.disabled,\n dev: env === 'development' || options.dev,\n });\n\n // Nothing to compile: keep the original code and map.\n if (result === null) {\n return null;\n }\n\n return {\n code: result.code,\n map: result.map,\n };\n },\n vite: {\n enforce: 'pre',\n configResolved(config): void {\n env = config.mode === 'production' ? 'production' : 'development';\n\n // run our plugin before the following plugins:\n // oxlint-disable-next-line typescript/no-unsafe-type-assertion\n repushPlugin(config.plugins as Plugin[], 'solid-labels', [\n // https://github.com/withastro/astro/blob/main/packages/astro/src/vite-plugin-jsx/index.ts#L173\n 'astro:jsx',\n // https://github.com/solidjs/vite-plugin-solid/blob/master/src/index.ts#L305\n 'solid',\n // https://github.com/solidjs/solid-start/blob/main/packages/start/vite/plugin.js#L118\n 'solid-start-file-system-router',\n ]);\n },\n },\n };\n});\n\nexport default solidLabelsPlugin;\n"],"mappings":";;;;AAQA,MAAM,kBAAkB;AACxB,MAAM,kBAAkB;AAExB,SAAS,YAAY,IAAoB;CACvC,MAAM,QAAQ,GAAG,QAAQ,GAAG;CAC5B,OAAO,UAAU,KAAK,KAAK,GAAG,MAAM,GAAG,KAAK;AAC9C;AAEA,SAAgB,eAAe,SAA4D;CACzF,MAAM,SAAS,aACb,SAAS,WAAW,iBACpB,SAAS,WAAW,eACtB;CACA,QAAQ,OAGN,OAAO,YAAY,EAAE,CAAC;AAC1B;;ACVA,SAAS,aAAa,SAAmB,YAAoB,aAA6B;CACxF,MAAM,WAAW,IAAI,IAAI,WAAW;CAEpC,IAAI,YAAY;CAChB,IAAI,cAAc;CAClB,IAAI;CACJ,KAAK,IAAI,IAAI,GAAG,MAAM,QAAQ,QAAQ,IAAI,KAAK,KAAK,GAAG;EACrD,MAAM,UAAU,QAAQ;EACxB,IAAI,SAAS,IAAI,QAAQ,IAAI,KAAK,cAAc,IAC9C,YAAY;EAEd,IAAI,QAAQ,SAAS,YAAY;GAC/B,cAAc;GACd,eAAe;EACjB;CACF;CACA,IAAI,gBAAgB,cAAc,MAAM,gBAAgB,MAAM,YAAY,aAAa;EACrF,QAAQ,OAAO,aAAa,CAAC;EAC7B,QAAQ,OAAO,WAAW,GAAG,YAAY;CAC3C;AACF;AAEA,MAAM,oBAAoB,gBAAgB,eAA0C;CAClF,MAAM,UAAU,cAAc,CAAC;CAC/B,MAAM,SAAS,eAAe,QAAQ,MAAM;CAE5C,IAAI;CAEJ,OAAO;EACL,MAAM;EACN,iBAAiB,IAAa;GAC5B,OAAO,OAAO,EAAE;EAClB;EACA,UAAU,MAAM,IAA4B;GAC1C,MAAM,SAAS,QAAQ,IAAI,MAAM;IAC/B,UAAU,QAAQ;IAClB,KAAK,QAAQ,iBAAiB,QAAQ;GACxC,CAAC;GAGD,IAAI,WAAW,MACb,OAAO;GAGT,OAAO;IACL,MAAM,OAAO;IACb,KAAK,OAAO;GACd;EACF;EACA,MAAM;GACJ,SAAS;GACT,eAAe,QAAc;IAC3B,MAAM,OAAO,SAAS,eAAe,eAAe;IAIpD,aAAa,OAAO,SAAqB,gBAAgB;KAEvD;KAEA;KAEA;IACF,CAAC;GACH;EACF;CACF;AACF,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "unplugin-solid-labels",
3
- "version": "0.17.1",
3
+ "version": "1.0.0",
4
4
  "private": false,
5
5
  "description": "Unplugin for solid-labels",
6
6
  "keywords": [
@@ -25,36 +25,30 @@
25
25
  "src"
26
26
  ],
27
27
  "type": "module",
28
- "main": "./dist/index.cjs",
29
- "module": "./dist/index.mjs",
30
- "types": "./dist/index.d.cts",
31
28
  "exports": {
32
- ".": {
33
- "import": "./dist/index.mjs",
34
- "require": "./dist/index.cjs"
35
- },
29
+ ".": "./dist/index.mjs",
36
30
  "./package.json": "./package.json"
37
31
  },
38
32
  "publishConfig": {
39
33
  "access": "public"
40
34
  },
41
35
  "dependencies": {
42
- "@babel/core": "^7.29.7",
43
- "@rollup/pluginutils": "^5.4.0",
44
- "unplugin": "^2.3.11"
36
+ "@rollup/pluginutils": "^5.5.1",
37
+ "unplugin": "^3.7.0"
45
38
  },
46
39
  "devDependencies": {
47
- "@types/babel__core": "^7.20.5",
48
- "@types/node": "^26.6.5",
49
- "rollup": "^4.64.6",
50
- "solid-labels": "0.17.1",
51
- "tsdown": "^0.23.1",
40
+ "@types/node": "^26.6.6",
41
+ "rollup": "^4.67.5",
42
+ "solid-labels": "1.0.0",
43
+ "tsdown": "^0.23.7",
44
+ "tslib": "^2.9.1",
52
45
  "typescript": "^7.0.2",
53
- "vite": "^8.3.4"
46
+ "vite": "^8.3.6",
47
+ "vitest": "^5.1.0"
54
48
  },
55
49
  "peerDependencies": {
56
- "rollup": "^3 || ^4",
57
- "solid-labels": "^0.17.1",
50
+ "rollup": "^3 || 4",
51
+ "solid-labels": "^1.0.0",
58
52
  "vite": "^3 || ^4 || ^5 || ^6 || ^7 || ^8"
59
53
  },
60
54
  "peerDependenciesMeta": {
@@ -70,6 +64,7 @@
70
64
  },
71
65
  "scripts": {
72
66
  "build": "tsdown",
73
- "watch": "tsdown --watch"
67
+ "watch": "tsdown --watch",
68
+ "test": "vitest run"
74
69
  }
75
70
  }
package/src/filter.ts ADDED
@@ -0,0 +1,26 @@
1
+ import type { FilterPattern } from '@rollup/pluginutils';
2
+ import { createFilter } from '@rollup/pluginutils';
3
+
4
+ export interface SolidLabelsPluginFilter {
5
+ include?: FilterPattern;
6
+ exclude?: FilterPattern;
7
+ }
8
+
9
+ const DEFAULT_INCLUDE = 'src/**/*.{jsx,tsx,ts,js,mjs,cjs}';
10
+ const DEFAULT_EXCLUDE = 'node_modules/**/*.{jsx,tsx,ts,js,mjs,cjs}';
11
+
12
+ function removeQuery(id: string): string {
13
+ const index = id.indexOf('?');
14
+ return index === -1 ? id : id.slice(0, index);
15
+ }
16
+
17
+ export function createIdFilter(options?: SolidLabelsPluginFilter): (id: string) => boolean {
18
+ const filter = createFilter(
19
+ options?.include ?? DEFAULT_INCLUDE,
20
+ options?.exclude ?? DEFAULT_EXCLUDE,
21
+ );
22
+ return (id) =>
23
+ // Bundlers can add a query to a module id, as SolidStart does with
24
+ // `?pick=` for route files. Match the file path without it.
25
+ filter(removeQuery(id));
26
+ }
package/src/index.ts CHANGED
@@ -1,17 +1,12 @@
1
- import * as babel from '@babel/core';
2
- import type { FilterPattern } from '@rollup/pluginutils';
3
- import { createFilter } from '@rollup/pluginutils';
4
- import path from 'node:path';
5
- import type { Options } from 'solid-labels/babel';
6
- import solidLabelsBabel from 'solid-labels/babel';
1
+ import type { Options } from 'solid-labels/compiler';
2
+ import { compile } from 'solid-labels/compiler';
7
3
  import type { TransformResult } from 'unplugin';
8
4
  import { createUnplugin } from 'unplugin';
9
5
  import type { Plugin } from 'vite';
6
+ import type { SolidLabelsPluginFilter } from './filter';
7
+ import { createIdFilter } from './filter';
10
8
 
11
- export interface SolidLabelsPluginFilter {
12
- include?: FilterPattern;
13
- exclude?: FilterPattern;
14
- }
9
+ export type { SolidLabelsPluginFilter };
15
10
 
16
11
  export interface SolidLabelsPluginOptions extends Options {
17
12
  filter?: SolidLabelsPluginFilter;
@@ -40,17 +35,9 @@ function repushPlugin(plugins: Plugin[], pluginName: string, pluginNames: string
40
35
  }
41
36
  }
42
37
 
43
- const DEFAULT_INCLUDE = 'src/**/*.{jsx,tsx,ts,js,mjs,cjs}';
44
- const DEFAULT_EXCLUDE = 'node_modules/**/*.{jsx,tsx,ts,js,mjs,cjs}';
45
-
46
- const FILE_FILTER = /\.[mc]?tsx?$/i;
47
-
48
38
  const solidLabelsPlugin = createUnplugin((rawOptions?: SolidLabelsPluginOptions) => {
49
39
  const options = rawOptions ?? {};
50
- const filter = createFilter(
51
- options.filter?.include ?? DEFAULT_INCLUDE,
52
- options.filter?.exclude ?? DEFAULT_EXCLUDE,
53
- );
40
+ const filter = createIdFilter(options.filter);
54
41
 
55
42
  let env: string;
56
43
 
@@ -59,41 +46,21 @@ const solidLabelsPlugin = createUnplugin((rawOptions?: SolidLabelsPluginOptions)
59
46
  transformInclude(id): boolean {
60
47
  return filter(id);
61
48
  },
62
- async transform(code, id): Promise<TransformResult> {
63
- const plugins: NonNullable<NonNullable<babel.TransformOptions['parserOpts']>['plugins']> = [
64
- 'jsx',
65
- ];
66
- if (FILE_FILTER.test(id)) {
67
- plugins.push('typescript');
68
- }
69
- const result = await babel.transformAsync(code, {
70
- plugins: [
71
- [
72
- solidLabelsBabel,
73
- {
74
- disabled: options.disabled,
75
- dev: env === 'development' || options.dev,
76
- },
77
- ],
78
- ],
79
- parserOpts: {
80
- plugins,
81
- },
82
- filename: path.basename(id),
83
- ast: false,
84
- sourceMaps: true,
85
- configFile: false,
86
- babelrc: false,
87
- sourceFileName: id,
49
+ transform(code, id): TransformResult | null {
50
+ const result = compile(id, code, {
51
+ disabled: options.disabled,
52
+ dev: env === 'development' || options.dev,
88
53
  });
89
54
 
90
- if (result) {
91
- return {
92
- code: result.code ?? '',
93
- map: result.map,
94
- };
55
+ // Nothing to compile: keep the original code and map.
56
+ if (result === null) {
57
+ return null;
95
58
  }
96
- return undefined;
59
+
60
+ return {
61
+ code: result.code,
62
+ map: result.map,
63
+ };
97
64
  },
98
65
  vite: {
99
66
  enforce: 'pre',
package/dist/index.cjs DELETED
@@ -1,97 +0,0 @@
1
- //#region \0rolldown/runtime.js
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __copyProps = (to, from, except, desc) => {
9
- if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
- key = keys[i];
11
- if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
- get: ((k) => from[k]).bind(null, key),
13
- enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
- });
15
- }
16
- return to;
17
- };
18
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
19
- value: mod,
20
- enumerable: true
21
- }) : target, mod));
22
- //#endregion
23
- let _babel_core = require("@babel/core");
24
- _babel_core = __toESM(_babel_core, 1);
25
- let _rollup_pluginutils = require("@rollup/pluginutils");
26
- let node_path = require("node:path");
27
- node_path = __toESM(node_path, 1);
28
- let solid_labels_babel = require("solid-labels/babel");
29
- solid_labels_babel = __toESM(solid_labels_babel, 1);
30
- let unplugin = require("unplugin");
31
- //#region src/index.ts
32
- function repushPlugin(plugins, pluginName, pluginNames) {
33
- const namesSet = new Set(pluginNames);
34
- let baseIndex = -1;
35
- let targetIndex = -1;
36
- let targetPlugin;
37
- for (let i = 0, len = plugins.length; i < len; i += 1) {
38
- const current = plugins[i];
39
- if (namesSet.has(current.name) && baseIndex === -1) baseIndex = i;
40
- if (current.name === pluginName) {
41
- targetIndex = i;
42
- targetPlugin = current;
43
- }
44
- }
45
- if (targetPlugin && baseIndex !== -1 && targetIndex !== -1 && baseIndex < targetIndex) {
46
- plugins.splice(targetIndex, 1);
47
- plugins.splice(baseIndex, 0, targetPlugin);
48
- }
49
- }
50
- const DEFAULT_INCLUDE = "src/**/*.{jsx,tsx,ts,js,mjs,cjs}";
51
- const DEFAULT_EXCLUDE = "node_modules/**/*.{jsx,tsx,ts,js,mjs,cjs}";
52
- const FILE_FILTER = /\.[mc]?tsx?$/i;
53
- const solidLabelsPlugin = (0, unplugin.createUnplugin)((rawOptions) => {
54
- const options = rawOptions ?? {};
55
- const filter = (0, _rollup_pluginutils.createFilter)(options.filter?.include ?? DEFAULT_INCLUDE, options.filter?.exclude ?? DEFAULT_EXCLUDE);
56
- let env;
57
- return {
58
- name: "solid-labels",
59
- transformInclude(id) {
60
- return filter(id);
61
- },
62
- async transform(code, id) {
63
- const plugins = ["jsx"];
64
- if (FILE_FILTER.test(id)) plugins.push("typescript");
65
- const result = await _babel_core.transformAsync(code, {
66
- plugins: [[solid_labels_babel.default, {
67
- disabled: options.disabled,
68
- dev: env === "development" || options.dev
69
- }]],
70
- parserOpts: { plugins },
71
- filename: node_path.default.basename(id),
72
- ast: false,
73
- sourceMaps: true,
74
- configFile: false,
75
- babelrc: false,
76
- sourceFileName: id
77
- });
78
- if (result) return {
79
- code: result.code ?? "",
80
- map: result.map
81
- };
82
- },
83
- vite: {
84
- enforce: "pre",
85
- configResolved(config) {
86
- env = config.mode === "production" ? "production" : "development";
87
- repushPlugin(config.plugins, "solid-labels", [
88
- "astro:jsx",
89
- "solid",
90
- "solid-start-file-system-router"
91
- ]);
92
- }
93
- }
94
- };
95
- });
96
- //#endregion
97
- module.exports = solidLabelsPlugin;
package/dist/index.d.cts DELETED
@@ -1,14 +0,0 @@
1
- import { FilterPattern } from "@rollup/pluginutils";
2
- import { Options } from "solid-labels/babel";
3
- //#region src/index.d.ts
4
- export interface SolidLabelsPluginFilter {
5
- include?: FilterPattern;
6
- exclude?: FilterPattern;
7
- }
8
- export interface SolidLabelsPluginOptions extends Options {
9
- filter?: SolidLabelsPluginFilter;
10
- }
11
- declare const solidLabelsPlugin: import("unplugin").UnpluginInstance<SolidLabelsPluginOptions | undefined, boolean>;
12
- //#endregion
13
- export { solidLabelsPlugin as default };
14
- //# sourceMappingURL=index.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.cts","names":[],"sources":["../src/index.ts"],"mappings":";;;iBAUiB;EACf,UAAU;EACV,UAAU;;iBAGK,iCAAiC;EAChD,SAAS;;cA+BL,sCAAiB,iBAAA"}