@lls/vitescripts 24.0.2 → 24.0.3-a03c8676c

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.2",
3
+ "version": "24.0.3-a03c8676c",
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,23 +1,34 @@
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('../')
6
7
 
7
8
  // sideRefreshActiveModules is of the form ['viewer', 'superkit', ...] with 'viewer' if repo launched
8
9
  // WITH_VIEWER=1 npm start
9
- export const makeSideRefreshThemeInterceptor = async (sideRefreshActiveModules) => {
10
- const parentDir = path.basename(path.dirname(process.cwd()))
10
+ export const makeSideRefreshThemeInterceptor = async (sideRefreshActiveModules = []) => {
11
+ const isMonorepo = path.basename(searchForWorkspaceRoot(pwd)) !== 'vitescripts'
12
+ const parentDir = path.basename(path.dirname(pwd))
11
13
  const sideRefreshThemes = {}
12
- const cssThemeMap = {
13
- viewer: path.join(pwd, '../viewer/src/utils/css-bare.mjs'),
14
- // kit: no themes for kit
15
- superkit: path.join(pwd, '../superkit/src/internals/utils/css-bare.mjs'),
16
- core: path.join(pwd, '../core/src/utils/css-bare.mjs'),
17
- audio: path.join(pwd, '../lls-audio/src/utils/css-bare.mjs'),
18
- code: path.join(pwd, '../lls-code/src/utils/css-bare.mjs')
19
- }
20
- await Promise.all(Object.keys(cssThemeMap).map(sideRefreshName => {
14
+ const cssThemeMap = isMonorepo
15
+ ? {
16
+ viewer: path.join(pwd, '../viewer/src/utils/css-bare.mjs'),
17
+ // kit: no themes for kit
18
+ superkit: path.join(pwd, '../superkit/src/internals/utils/css-bare.mjs'),
19
+ core: path.join(pwd, '../core/src/utils/css-bare.mjs'),
20
+ audio: path.join(pwd, '../lls-audio/src/utils/css-bare.mjs'),
21
+ code: path.join(pwd, '../lls-code/src/utils/css-bare.mjs')
22
+ }
23
+ : {
24
+ viewer: '@lls/viewer/lib/css-bare.mjs',
25
+ // kit: no themes for kit
26
+ superkit: '@lls/superkit/lib/css-bare.mjs',
27
+ core: '@lls/core/lib/css-bare.mjs',
28
+ audio: '@lls/lls-audio/lib/css-bare.mjs',
29
+ code: '@lls/lls-code/lib/css-bare.mjs'
30
+ }
31
+ await Promise.all((isMonorepo ? Object.keys(cssThemeMap) : sideRefreshActiveModules).map(sideRefreshName => {
21
32
  if (!cssThemeMap[sideRefreshName]) {
22
33
  throw new Error('invalid side refresh name' + sideRefreshName)
23
34
  }
@@ -28,7 +39,7 @@ export const makeSideRefreshThemeInterceptor = async (sideRefreshActiveModules)
28
39
  sideRefreshThemes[`${sideRefreshName}_light`] = mod.themeIsNotDarkMode
29
40
  })
30
41
  }))
31
- const folderRegex = new RegExp(Object.keys(sideRefreshThemes).map(capName => parentDir + '/' + capName.split('_')[0]).join('|'))
42
+ const folderRegex = new RegExp([...new Set(Object.keys(sideRefreshThemes).map(capName => parentDir + '/' + capName.split('_')[0]))].join('|'))
32
43
  return (cap, id, next) => {
33
44
  const match = id.match(folderRegex)?.[0]
34
45
  cap = match ? `${match.split('/')[1]}_${cap}` : cap
@@ -42,7 +53,8 @@ export const makeSideRefreshThemeInterceptor = async (sideRefreshActiveModules)
42
53
  * @returns a plugin to pass to vite and aliases for sideRefreshed packages
43
54
  */
44
55
  const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iSuperkit, kit: iKit, utils: iUtils, core: iCore, code: iCode }, { client, publicDir = 'ladleassets' } = {}) => {
45
- const pwd = process.cwd()
56
+ const isMonorepo = path.basename(searchForWorkspaceRoot(pwd)) !== 'vitescripts'
57
+ // TODO: imports from clientImports does not work for now
46
58
  let activeModules = []
47
59
  if ([iViewer, iSuperkit, iKit, iUtils, iCore, iCode, iAudio].some(x => x)) {
48
60
  activeModules = [
@@ -107,7 +119,7 @@ const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iS
107
119
  let promise = ''
108
120
  const getPromise = () => {
109
121
  if (client && !pwd.includes(basename.replace('.css', ''))) {
110
- promise = fs.promises.readFile(key(basename), 'utf8')
122
+ promise = isMonorepo ? Promise.resolve('') : fs.promises.readFile(key(basename), 'utf8')
111
123
  }
112
124
  return promise
113
125
  }
@@ -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