defuss-astro 1.4.8 → 1.4.9

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.cjs CHANGED
@@ -2,7 +2,8 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var defussPlugin = require('defuss-vite');
5
+ var vite = require('vite');
6
+ var core = require('@swc/core');
6
7
  var node_url = require('node:url');
7
8
  var glob = require('fast-glob');
8
9
  var node_perf_hooks = require('node:perf_hooks');
@@ -12,6 +13,90 @@ var promises = require('node:fs/promises');
12
13
  var purgecss = require('purgecss');
13
14
  var node_fs = require('node:fs');
14
15
 
16
+ function parseId(url) {
17
+ return { id: url.split("?", 2)[0] };
18
+ }
19
+ function defussVitePlugin({
20
+ include,
21
+ exclude
22
+ } = {}) {
23
+ let config;
24
+ const shouldTransform = vite.createFilter(
25
+ include || [/\.[cm]?[tj]sx?$/],
26
+ exclude || [/node_modules/]
27
+ );
28
+ const jsxPlugin = {
29
+ name: "vite:defuss-jsx",
30
+ enforce: "pre",
31
+ config() {
32
+ return {
33
+ esbuild: {
34
+ // we want Vite to handle JSX transformations
35
+ jsxImportSource: "defuss",
36
+ jsxFactory: "jsx",
37
+ jsxFragment: "Fragment"
38
+ },
39
+ optimizeDeps: {
40
+ // we want Vite to optimize the runtime code
41
+ include: ["defuss"],
42
+ // we don't want Vite to optimize this plugin code
43
+ exclude: ["defuss-vite"]
44
+ },
45
+ ssr: {
46
+ // LinkeDOM (used by defuss/render) imports perf_hooks
47
+ // which is actually just an empty placeholder package,
48
+ // therefore, we externalize it
49
+ external: ["perf_hooks"]
50
+ }
51
+ };
52
+ },
53
+ configResolved(resolvedConfig) {
54
+ config = resolvedConfig;
55
+ },
56
+ async transform(code, url) {
57
+ const { id } = parseId(url);
58
+ if (!shouldTransform(id)) {
59
+ return null;
60
+ }
61
+ const prevSourceMap = this.getCombinedSourcemap?.();
62
+ const inputSourceMap = prevSourceMap ? JSON.stringify({ code, map: prevSourceMap }) : void 0;
63
+ const result = await core.transform(code, {
64
+ jsc: {
65
+ parser: {
66
+ syntax: "typescript",
67
+ tsx: true,
68
+ dynamicImport: true,
69
+ decorators: true
70
+ },
71
+ transform: {
72
+ react: {
73
+ development: true,
74
+ useBuiltins: false,
75
+ throwIfNamespace: false,
76
+ pragma: "jsx",
77
+ pragmaFrag: "Fragment",
78
+ runtime: "automatic",
79
+ importSource: "defuss"
80
+ }
81
+ },
82
+ target: "es2024"
83
+ },
84
+ sourceMaps: true,
85
+ sourceFileName: id,
86
+ filename: id,
87
+ sourceRoot: config.root,
88
+ inputSourceMap
89
+ });
90
+ if (!result) return null;
91
+ return {
92
+ code: result.code || code,
93
+ map: result.map
94
+ };
95
+ }
96
+ };
97
+ return jsxPlugin;
98
+ }
99
+
15
100
  const logMessage = (message) => {
16
101
  const date = (/* @__PURE__ */ new Date()).toLocaleTimeString();
17
102
  console.log(`${date} \x1B[32mdefuss-astro:\x1B[0m ${message}`);
@@ -101,7 +186,7 @@ function index({
101
186
  ssr: {
102
187
  noExternal: ["lightningimg-node"]
103
188
  },
104
- plugins: [defussPlugin()]
189
+ plugins: [defussVitePlugin()]
105
190
  }
106
191
  });
107
192
  },
package/dist/index.d.cts CHANGED
@@ -1,5 +1,16 @@
1
1
  import { AstroIntegration, ContainerRenderer } from 'astro';
2
- import { DefussVitePluginOptions } from 'defuss-vite';
2
+ import { FilterPattern } from 'vite';
3
+
4
+ interface DefussVitePluginOptions {
5
+ /**
6
+ * RegExp or glob to match files to be transformed
7
+ */
8
+ include?: FilterPattern;
9
+ /**
10
+ * RegExp or glob to match files to NOT be transformed
11
+ */
12
+ exclude?: FilterPattern;
13
+ }
3
14
 
4
15
  interface Options extends Pick<DefussVitePluginOptions, "exclude" | "include"> {
5
16
  devtools?: boolean;
package/dist/index.d.mts CHANGED
@@ -1,5 +1,16 @@
1
1
  import { AstroIntegration, ContainerRenderer } from 'astro';
2
- import { DefussVitePluginOptions } from 'defuss-vite';
2
+ import { FilterPattern } from 'vite';
3
+
4
+ interface DefussVitePluginOptions {
5
+ /**
6
+ * RegExp or glob to match files to be transformed
7
+ */
8
+ include?: FilterPattern;
9
+ /**
10
+ * RegExp or glob to match files to NOT be transformed
11
+ */
12
+ exclude?: FilterPattern;
13
+ }
3
14
 
4
15
  interface Options extends Pick<DefussVitePluginOptions, "exclude" | "include"> {
5
16
  devtools?: boolean;
package/dist/index.mjs CHANGED
@@ -1,4 +1,5 @@
1
- import defussPlugin from 'defuss-vite';
1
+ import { createFilter } from 'vite';
2
+ import { transform } from '@swc/core';
2
3
  import { fileURLToPath } from 'node:url';
3
4
  import glob from 'fast-glob';
4
5
  import { performance } from 'node:perf_hooks';
@@ -8,6 +9,90 @@ import { readFile, writeFile } from 'node:fs/promises';
8
9
  import { PurgeCSS } from 'purgecss';
9
10
  import { existsSync } from 'node:fs';
10
11
 
12
+ function parseId(url) {
13
+ return { id: url.split("?", 2)[0] };
14
+ }
15
+ function defussVitePlugin({
16
+ include,
17
+ exclude
18
+ } = {}) {
19
+ let config;
20
+ const shouldTransform = createFilter(
21
+ include || [/\.[cm]?[tj]sx?$/],
22
+ exclude || [/node_modules/]
23
+ );
24
+ const jsxPlugin = {
25
+ name: "vite:defuss-jsx",
26
+ enforce: "pre",
27
+ config() {
28
+ return {
29
+ esbuild: {
30
+ // we want Vite to handle JSX transformations
31
+ jsxImportSource: "defuss",
32
+ jsxFactory: "jsx",
33
+ jsxFragment: "Fragment"
34
+ },
35
+ optimizeDeps: {
36
+ // we want Vite to optimize the runtime code
37
+ include: ["defuss"],
38
+ // we don't want Vite to optimize this plugin code
39
+ exclude: ["defuss-vite"]
40
+ },
41
+ ssr: {
42
+ // LinkeDOM (used by defuss/render) imports perf_hooks
43
+ // which is actually just an empty placeholder package,
44
+ // therefore, we externalize it
45
+ external: ["perf_hooks"]
46
+ }
47
+ };
48
+ },
49
+ configResolved(resolvedConfig) {
50
+ config = resolvedConfig;
51
+ },
52
+ async transform(code, url) {
53
+ const { id } = parseId(url);
54
+ if (!shouldTransform(id)) {
55
+ return null;
56
+ }
57
+ const prevSourceMap = this.getCombinedSourcemap?.();
58
+ const inputSourceMap = prevSourceMap ? JSON.stringify({ code, map: prevSourceMap }) : void 0;
59
+ const result = await transform(code, {
60
+ jsc: {
61
+ parser: {
62
+ syntax: "typescript",
63
+ tsx: true,
64
+ dynamicImport: true,
65
+ decorators: true
66
+ },
67
+ transform: {
68
+ react: {
69
+ development: true,
70
+ useBuiltins: false,
71
+ throwIfNamespace: false,
72
+ pragma: "jsx",
73
+ pragmaFrag: "Fragment",
74
+ runtime: "automatic",
75
+ importSource: "defuss"
76
+ }
77
+ },
78
+ target: "es2024"
79
+ },
80
+ sourceMaps: true,
81
+ sourceFileName: id,
82
+ filename: id,
83
+ sourceRoot: config.root,
84
+ inputSourceMap
85
+ });
86
+ if (!result) return null;
87
+ return {
88
+ code: result.code || code,
89
+ map: result.map
90
+ };
91
+ }
92
+ };
93
+ return jsxPlugin;
94
+ }
95
+
11
96
  const logMessage = (message) => {
12
97
  const date = (/* @__PURE__ */ new Date()).toLocaleTimeString();
13
98
  console.log(`${date} \x1B[32mdefuss-astro:\x1B[0m ${message}`);
@@ -97,7 +182,7 @@ function index({
97
182
  ssr: {
98
183
  noExternal: ["lightningimg-node"]
99
184
  },
100
- plugins: [defussPlugin()]
185
+ plugins: [defussVitePlugin()]
101
186
  }
102
187
  });
103
188
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "defuss-astro",
3
- "version": "1.4.8",
3
+ "version": "1.4.9",
4
4
  "type": "module",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -78,7 +78,7 @@
78
78
  },
79
79
  "dependencies": {
80
80
  "defuss": "^2.1.10",
81
- "defuss-vite": "^1.1.3",
81
+ "@swc/core": "^1.10.2",
82
82
  "astro": "^5.16.11",
83
83
  "vite": "^6.4.1",
84
84
  "fast-glob": "^3.3.3",