@lls/vitescripts 24.0.1-949326475 → 24.0.1-994004eea

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": "24.0.1-949326475",
3
+ "version": "24.0.1-994004eea",
4
4
  "description": "lls vite plugins",
5
5
  "main": "src/index.mjs",
6
6
  "files": [
@@ -9,7 +9,8 @@
9
9
  "dependencies": {
10
10
  "browserslist": "4.22.1",
11
11
  "esbuild-plugin-lightningcss-modules": "0.1.1",
12
- "lightningcss": "1.22.1"
12
+ "lightningcss": "1.22.1",
13
+ "vite": "5.0.5"
13
14
  },
14
15
  "type": "module",
15
16
  "author": "",
package/src/index.mjs CHANGED
@@ -1,9 +1,6 @@
1
1
  export { default as llsAssetsPlugin } from './llsAssetsPlugin.mjs'
2
- export { default as llsLinariaImportsPlugin } from './llsLinariaImportsPlugin.mjs'
3
2
  export { default as llsCssSsrCollectPlugin } from './llsCssSsrCollectPlugin.mjs'
4
3
  export { default as llsSideRefreshMetaPlugin } from './llsSideRefreshMetaPlugin.mjs'
5
- export { default as llsVitestMockPlugin } from './llsVitestMockPlugin.mjs'
6
- export { default as llsLadlePlugin } from './llsLadlePlugin.mjs'
7
4
  export { default as llsCssModuleMacroPlugin } from './llsCssModuleMacroPlugin.mjs'
8
5
  export { default as postBuildAutoprefixerPlugin } from './postBuildAutoprefixerPlugin.mjs'
9
6
  export { default as esbuildCssModulePlugin } from './esbuildCssModulePlugin.mjs'
@@ -3,7 +3,6 @@ import { promisify } from 'util'
3
3
  import { exec } from 'node:child_process'
4
4
  import path from 'path'
5
5
  const execP = promisify(exec)
6
-
7
6
  // https://github.com/vitejs/vite/pull/8574
8
7
  /**
9
8
  * Plugin that will copy assets from given repos to public dir of launched project
@@ -12,6 +11,7 @@ const execP = promisify(exec)
12
11
  * @returns config() method that copies assets
13
12
  * transform() method that replaces assets path to be resolved
14
13
  */
14
+ const toLocal = pkgName => new URL(pkgName, import.meta.url).pathname
15
15
  const llsAssetsPlugin = (llsRepos, publicDir = 'ladleassets', { stripRoot = true } = {}) => {
16
16
  const publicAssetDir = path.join(publicDir, 'assets')
17
17
  const fileExists = (s) => new Promise(resolve => fs.access(s, e => resolve(!e)))
@@ -23,38 +23,6 @@ const llsAssetsPlugin = (llsRepos, publicDir = 'ladleassets', { stripRoot = true
23
23
  }
24
24
  return {
25
25
  name: 'lls:copyassets',
26
- async config () {
27
- await execP(`mkdir -p ${publicAssetDir}`)
28
- const pnpmNameToPath = await execP('pnpm ls -r @lls/lls-drawer --json'/*'pnpm ls -r -d 0 --json'*/)
29
- .then(({ stdout }) => JSON.parse(stdout))
30
- .then(json => {
31
- let drawer = null
32
- const back = json.map(({ name, path, dependencies }) => {
33
- if (dependencies?.['@lls/lls-drawer']?.path) {
34
- drawer = ['@lls/lls-drawer', dependencies?.['@lls/lls-drawer']?.path + '/lib/assets/*']
35
- }
36
- return [name, path + '/lib/assets/*']
37
- })
38
- return back.concat(drawer ? [drawer] : [])
39
- })
40
- .then(Object.fromEntries)
41
- .catch(e => {})
42
- const repoArgs = await Promise.all(llsRepos.map(async repo => {
43
- if (!repo.startsWith('@')) return repo
44
- const pnpmPath = pnpmNameToPath[repo]
45
- if (pnpmPath) return pnpmPath
46
-
47
- const aPath = 'lib/assets/*'
48
- const prefix = await fileExists(`${process.cwd()}/node_modules/${repo}`)
49
- ? `${process.cwd()}/node_modules/${repo}`
50
- : `${process.cwd()}/node_modules/.pnpm/${repo}`
51
- return path.join(prefix, aPath)
52
- }))
53
- repoArgs.push('static/assets/*')
54
- for (const repo of repoArgs) {
55
- await execP(`cp -rf ${repo} ${publicAssetDir}`)
56
- }
57
- },
58
26
  ...(stripRoot && {
59
27
  transform (src, id) {
60
28
  if (
@@ -39,7 +39,7 @@ const llsCssModuleMacroPlugin = async ({ themeIsFreeMode, themeIsDarkMode, theme
39
39
  return interceptSideRefreshTheme(cap, id, (cap) => {
40
40
  const back = cssMacroTheme[cap]
41
41
  if (!back) {
42
- throw new Error('llsCssModuleMacroPlugin::missing definition for ' + cap)
42
+ throw new Error('llsCssModuleMacroPlugin::missing definition for ' + cap+ '('+id+')')
43
43
  }
44
44
  return back
45
45
  })
@@ -1,5 +1,6 @@
1
1
  import fs from 'fs'
2
2
  import path from 'path'
3
+ import { searchForWorkspaceRoot } from 'vite'
3
4
 
4
5
  const toLocal = pkgName => new URL(pkgName, import.meta.url).pathname
5
6
  const pwd = toLocal('../')
@@ -7,7 +8,7 @@ const pwd = toLocal('../')
7
8
  // sideRefreshActiveModules is of the form ['viewer', 'superkit', ...] with 'viewer' if repo launched
8
9
  // WITH_VIEWER=1 npm start
9
10
  export const makeSideRefreshThemeInterceptor = async (sideRefreshActiveModules) => {
10
- const parentDir = path.basename(path.dirname(process.cwd()))
11
+ const parentDir = path.basename(path.dirname(pwd))
11
12
  const sideRefreshThemes = {}
12
13
  const cssThemeMap = {
13
14
  viewer: path.join(pwd, '../viewer/src/utils/css-bare.mjs'),
@@ -28,7 +29,7 @@ export const makeSideRefreshThemeInterceptor = async (sideRefreshActiveModules)
28
29
  sideRefreshThemes[`${sideRefreshName}_light`] = mod.themeIsNotDarkMode
29
30
  })
30
31
  }))
31
- const folderRegex = new RegExp(Object.keys(sideRefreshThemes).map(capName => parentDir + '/' + capName.split('_')[0]).join('|'))
32
+ const folderRegex = new RegExp([...new Set(Object.keys(sideRefreshThemes).map(capName => parentDir + '/' + capName.split('_')[0]))].join('|'))
32
33
  return (cap, id, next) => {
33
34
  const match = id.match(folderRegex)?.[0]
34
35
  cap = match ? `${match.split('/')[1]}_${cap}` : cap
@@ -42,7 +43,8 @@ export const makeSideRefreshThemeInterceptor = async (sideRefreshActiveModules)
42
43
  * @returns a plugin to pass to vite and aliases for sideRefreshed packages
43
44
  */
44
45
  const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iSuperkit, kit: iKit, utils: iUtils, core: iCore, code: iCode }, { client, publicDir = 'ladleassets' } = {}) => {
45
- const pwd = process.cwd()
46
+ const isMonorepo = path.basename(searchForWorkspaceRoot(pwd)) !== 'vitescripts'
47
+ // TODO: imports from clientImports does not work for now
46
48
  let activeModules = []
47
49
  if ([iViewer, iSuperkit, iKit, iUtils, iCore, iCode, iAudio].some(x => x)) {
48
50
  activeModules = [
@@ -107,7 +109,7 @@ const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iS
107
109
  let promise = ''
108
110
  const getPromise = () => {
109
111
  if (client && !pwd.includes(basename.replace('.css', ''))) {
110
- promise = fs.promises.readFile(key(basename), 'utf8')
112
+ promise = isMonorepo ? Promise.resolve('') : fs.promises.readFile(key(basename), 'utf8')
111
113
  }
112
114
  return promise
113
115
  }
@@ -1,16 +0,0 @@
1
- const llsLadlePlugin = (sbFolder) => ({
2
- name: 'lls:llsLadlePlugin',
3
- config (config, { command }) {
4
- const ladleCiEnv = /prod|tag|master|v\d/.test(process.env.LADLE_DEST) ? 'prod' : 'dev'
5
- return {
6
- base: command === 'serve' ? '/' : `https://build.lelivrescolaire.fr/storybook/${sbFolder}-${ladleCiEnv}/`,
7
- // base: command === 'serve' ? '/' : 'http://localhost:5000/ladledist/',
8
-
9
- build: {
10
- minify: false
11
- }
12
- }
13
- }
14
- })
15
-
16
- export default llsLadlePlugin
@@ -1,19 +0,0 @@
1
- const llsLinariaImports = ({ client } = {}) => {
2
- return {
3
- name: 'lls:linaria-imports',
4
- load (id) {
5
- console.log('llsLinariaImports plugin is deprecated, remove usage. Already handled by llsSideRefreshMetaPlugin')
6
- if (client) return
7
- if (id.endsWith('@lls/viewer/lib/assets/viewer.css')) { return '' }
8
- if (id.endsWith('@lls/superkit/lib/assets/superkit.css')) { return '' }
9
- if (id.endsWith('@lls/lls-kit/lib/assets/lls-kit.css') || id.endsWith('@lls/lls-kit/lib/assets/lls-kit-fonts.css')) {
10
- return ''
11
- }
12
- if (id.endsWith('@lls/lls-drawer/lib/assets/lls-drawer.css')) { return '' }
13
- if (id.endsWith('@lls/lls-code/lib/assets/lls-code.css')) { return '' }
14
- if (id.endsWith('@lls/core/lib/assets/core.css')) { return '' }
15
- }
16
- }
17
- }
18
-
19
- export default llsLinariaImports
@@ -1,14 +0,0 @@
1
- const llsVitestMock = () => ({
2
- name: 'lls:vitestmock',
3
- transform (code, id) {
4
- if (id.endsWith('@lls/viewer/lib/index.js')) {
5
- return code
6
- .replace(/require\("(@lls\/lls-audio|@lls\/lls-code|@yorab\/react-paint)"\)/g, (__, cap) => {
7
- if (cap === '@lls/lls-audio') return '{__esModule: true, default: () => null, Recorder: () => null}'
8
- return '{__esModule: true, default: () => null}'
9
- })
10
- }
11
- }
12
- })
13
-
14
- export default llsVitestMock