@lls/vitescripts 2.0.14 → 2.0.15

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lls/vitescripts",
3
- "version": "2.0.14",
3
+ "version": "2.0.15",
4
4
  "description": "lls vite plugins",
5
5
  "main": "src/index.mjs",
6
6
  "files": [
@@ -1,4 +1,5 @@
1
1
  import fs from 'fs'
2
+ import path from 'path'
2
3
  import llsCssModuleMacroPlugin from './llsCssModuleMacroPlugin.mjs'
3
4
  import { cssModules } from 'esbuild-plugin-lightningcss-modules'
4
5
 
@@ -8,22 +9,34 @@ export default ({ prefix = '', llsCssModuleMacroPluginArg }) => {
8
9
  drafts: { nesting: true },
9
10
  cssModulesPattern: `${prefix ? prefix + '-' : ''}[hash]-[local]`
10
11
  })
12
+ const tmpDir = path.join(process.cwd(), 'tmp_esbuild')
11
13
  return [
12
14
  {
13
15
  name: 'lls-cssmodule',
14
16
  async setup(build) {
17
+
18
+ await fs.promises.mkdir(tmpDir, { recursive: true })
15
19
  const llsCssModuleMacroPluginInstance = await llsCssModuleMacroPlugin(llsCssModuleMacroPluginArg)
20
+
21
+ // need to add the generated files to esbuild pipeline
22
+ build.onResolve({ filter: /tmp_esbuild/ }, async args => {
23
+ return { path: args.path }
24
+ })
16
25
  build.onLoad({ filter: /module\.css$/ }, async args => {
17
- if (args.path.startsWith('/tmp')) return
26
+ if (args.path.startsWith(tmpDir)) return
18
27
  const contents = await fs.promises.readFile(args.path, 'utf8').then(str => llsCssModuleMacroPluginInstance.transform(str, args.path))
19
28
  const id = args.path.replace(process.cwd(), '').replace(/\//g, '_')
20
- const outName = `/tmp/${id}`
21
- await fs.promises.writeFile(outName, contents)
29
+
30
+ const out = path.join(tmpDir, id)
31
+ await fs.promises.writeFile(out, contents)
22
32
  return {
23
- contents: `export { default } from '${outName}'`,
33
+ contents: `export { default } from '${out}'`,
24
34
  loader: 'js'
25
35
  }
26
36
  })
37
+ build.onDispose(async () => {
38
+ await fs.promises.rm(tmpDir, { recursive: true })
39
+ })
27
40
  }
28
41
  },
29
42
  esbuildCssModule