@lls/vitescripts 24.0.3-a03c8676c → 24.0.3

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.3-a03c8676c",
3
+ "version": "24.0.3",
4
4
  "description": "lls vite plugins",
5
5
  "main": "src/index.mjs",
6
6
  "files": [
@@ -9,8 +9,7 @@
9
9
  "dependencies": {
10
10
  "browserslist": "4.22.1",
11
11
  "esbuild-plugin-lightningcss-modules": "0.1.1",
12
- "lightningcss": "1.22.1",
13
- "vite": "5.0.5"
12
+ "lightningcss": "1.22.1"
14
13
  },
15
14
  "type": "module",
16
15
  "author": "",
package/src/index.mjs CHANGED
@@ -1,6 +1,9 @@
1
1
  export { default as llsAssetsPlugin } from './llsAssetsPlugin.mjs'
2
+ export { default as llsLinariaImportsPlugin } from './llsLinariaImportsPlugin.mjs'
2
3
  export { default as llsCssSsrCollectPlugin } from './llsCssSsrCollectPlugin.mjs'
3
4
  export { default as llsSideRefreshMetaPlugin } from './llsSideRefreshMetaPlugin.mjs'
5
+ export { default as llsVitestMockPlugin } from './llsVitestMockPlugin.mjs'
6
+ export { default as llsLadlePlugin } from './llsLadlePlugin.mjs'
4
7
  export { default as llsCssModuleMacroPlugin } from './llsCssModuleMacroPlugin.mjs'
5
8
  export { default as postBuildAutoprefixerPlugin } from './postBuildAutoprefixerPlugin.mjs'
6
9
  export { default as esbuildCssModulePlugin } from './esbuildCssModulePlugin.mjs'
@@ -3,6 +3,7 @@ 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
+
6
7
  // https://github.com/vitejs/vite/pull/8574
7
8
  /**
8
9
  * Plugin that will copy assets from given repos to public dir of launched project
@@ -11,7 +12,6 @@ const execP = promisify(exec)
11
12
  * @returns config() method that copies assets
12
13
  * transform() method that replaces assets path to be resolved
13
14
  */
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,6 +23,38 @@ 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
+ },
26
58
  ...(stripRoot && {
27
59
  transform (src, id) {
28
60
  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+ '('+id+')')
42
+ throw new Error('llsCssModuleMacroPlugin::missing definition for ' + cap)
43
43
  }
44
44
  return back
45
45
  })
@@ -0,0 +1,16 @@
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
@@ -0,0 +1,19 @@
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,34 +1,23 @@
1
1
  import fs from 'fs'
2
2
  import path from 'path'
3
- import { searchForWorkspaceRoot } from 'vite'
4
3
 
5
4
  const toLocal = pkgName => new URL(pkgName, import.meta.url).pathname
6
5
  const pwd = toLocal('../')
7
6
 
8
7
  // sideRefreshActiveModules is of the form ['viewer', 'superkit', ...] with 'viewer' if repo launched
9
8
  // WITH_VIEWER=1 npm start
10
- export const makeSideRefreshThemeInterceptor = async (sideRefreshActiveModules = []) => {
11
- const isMonorepo = path.basename(searchForWorkspaceRoot(pwd)) !== 'vitescripts'
12
- const parentDir = path.basename(path.dirname(pwd))
9
+ export const makeSideRefreshThemeInterceptor = async (sideRefreshActiveModules) => {
10
+ const parentDir = path.basename(path.dirname(process.cwd()))
13
11
  const sideRefreshThemes = {}
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 => {
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 => {
32
21
  if (!cssThemeMap[sideRefreshName]) {
33
22
  throw new Error('invalid side refresh name' + sideRefreshName)
34
23
  }
@@ -39,7 +28,7 @@ export const makeSideRefreshThemeInterceptor = async (sideRefreshActiveModules =
39
28
  sideRefreshThemes[`${sideRefreshName}_light`] = mod.themeIsNotDarkMode
40
29
  })
41
30
  }))
42
- const folderRegex = new RegExp([...new Set(Object.keys(sideRefreshThemes).map(capName => parentDir + '/' + capName.split('_')[0]))].join('|'))
31
+ const folderRegex = new RegExp(Object.keys(sideRefreshThemes).map(capName => parentDir + '/' + capName.split('_')[0]).join('|'))
43
32
  return (cap, id, next) => {
44
33
  const match = id.match(folderRegex)?.[0]
45
34
  cap = match ? `${match.split('/')[1]}_${cap}` : cap
@@ -53,8 +42,7 @@ export const makeSideRefreshThemeInterceptor = async (sideRefreshActiveModules =
53
42
  * @returns a plugin to pass to vite and aliases for sideRefreshed packages
54
43
  */
55
44
  const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iSuperkit, kit: iKit, utils: iUtils, core: iCore, code: iCode }, { client, publicDir = 'ladleassets' } = {}) => {
56
- const isMonorepo = path.basename(searchForWorkspaceRoot(pwd)) !== 'vitescripts'
57
- // TODO: imports from clientImports does not work for now
45
+ const pwd = process.cwd()
58
46
  let activeModules = []
59
47
  if ([iViewer, iSuperkit, iKit, iUtils, iCore, iCode, iAudio].some(x => x)) {
60
48
  activeModules = [
@@ -119,7 +107,7 @@ const llsSideRefreshMetaPlugin = ({ audio: iAudio, viewer: iViewer, superkit: iS
119
107
  let promise = ''
120
108
  const getPromise = () => {
121
109
  if (client && !pwd.includes(basename.replace('.css', ''))) {
122
- promise = isMonorepo ? Promise.resolve('') : fs.promises.readFile(key(basename), 'utf8')
110
+ promise = fs.promises.readFile(key(basename), 'utf8')
123
111
  }
124
112
  return promise
125
113
  }
@@ -0,0 +1,14 @@
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