@lls/vitescripts 2.0.22 → 2.0.23

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.22",
3
+ "version": "2.0.23",
4
4
  "description": "lls vite plugins",
5
5
  "main": "src/index.mjs",
6
6
  "files": [
package/src/index.mjs CHANGED
@@ -8,3 +8,4 @@ export { default as llsLadlePlugin } from './llsLadlePlugin.mjs'
8
8
  export { default as llsCssModuleMacroPlugin } from './llsCssModuleMacroPlugin.mjs'
9
9
  export { default as postBuildAutoprefixerPlugin } from './postBuildAutoprefixerPlugin.mjs'
10
10
  export { default as esbuildCssModulePlugin } from './esbuildCssModulePlugin.mjs'
11
+ export { default as postBuildTsTypesPlugin } from './postBuildTsTypes.mjs'
@@ -0,0 +1,36 @@
1
+ import fs from 'node:fs/promises'
2
+ import path from 'path'
3
+ import { exec } from 'child_process'
4
+ import util from 'util'
5
+ const execp = util.promisify(exec)
6
+
7
+ const getDirectoryFileNames = async directory => {
8
+ const fileNames = []
9
+ const filesInDirectory = await fs.readdir(directory)
10
+ for (const fileName of filesInDirectory) {
11
+ const absolute = path.join(directory, fileName)
12
+ if ((await fs.stat(absolute)).isDirectory()) {
13
+ fileNames.push(...await getDirectoryFileNames(absolute))
14
+ } else {
15
+ fileNames.push(absolute)
16
+ }
17
+ }
18
+ return fileNames
19
+ }
20
+
21
+ const postBuildTstypes = async ({ rootAliases = [] }) => {
22
+ try {
23
+ await fs.access('./builttypes', fs.constants.F_OK)
24
+ } catch (e) {
25
+ return
26
+ }
27
+ const fileNames = await getDirectoryFileNames('./builttypes')
28
+ const rootAliasRegex = new RegExp(rootAliases.map(x => x + '/').join('|') || 'nevermatching/', 'g')
29
+ for (const fileName of fileNames) {
30
+ await fs.readFile(fileName, 'utf8').then(
31
+ str => str.replaceAll(rootAliasRegex, `${path.relative(fileName, 'builttypes').slice(1)}/`) // builttypes/index.ts will be resolved to '..' so we always remove the first dot
32
+ ).then(outStr => fs.writeFile(fileName, outStr))
33
+ }
34
+ await execp('cp -r builttypes/. lib')
35
+ }
36
+ export default postBuildTstypes