@lls/vitescripts 1.1.0 → 1.1.1

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": "1.1.0",
3
+ "version": "1.1.1",
4
4
  "description": "lls vite plugins",
5
5
  "main": "src/index.mjs",
6
6
  "files": [
@@ -5,6 +5,13 @@ import path from 'path'
5
5
  const execP = promisify(exec)
6
6
 
7
7
  // https://github.com/vitejs/vite/pull/8574
8
+ /**
9
+ * Plugin that will copy assets from given repos to public dir of launched project
10
+ * @param {*} llsRepos array containing names of the repos
11
+ * @param {*} publicDir public dir to copy assets to
12
+ * @returns config() method that copies assets
13
+ * transform() method that replaces assets path to be resolved
14
+ */
8
15
  const llsAssetsPlugin = (llsRepos, publicDir = 'ladleassets') => {
9
16
  const publicAssetDir = path.join(publicDir, 'assets')
10
17
  const fileExists = (s) => new Promise(resolve => fs.access(s, e => resolve(!e)))
@@ -12,7 +19,7 @@ const llsAssetsPlugin = (llsRepos, publicDir = 'ladleassets') => {
12
19
  const storyRoot = process.cwd() + '/stories'
13
20
  return {
14
21
  name: 'lls:copyassets',
15
- async config(conf, { command }) {
22
+ async config() {
16
23
  await execP(`mkdir -p ${publicAssetDir}`)
17
24
  const repoArgs = await Promise.all(llsRepos.map(async repo => {
18
25
  if (!repo.startsWith('@')) return repo
@@ -1,3 +1,9 @@
1
+ /**
2
+ * Plugin that collects styles from linaria cache to inject it in the page.
3
+ * @returns config() method that instantiates linariaPlugin
4
+ * resolveId() method that filters files to be added to css set
5
+ * flushStyles() method that generates and return <style> tag with refreshed style
6
+ */
1
7
  const llsLinariaSsrCollectPlugin = () => {
2
8
  const cssIds = new Set()
3
9
  let linariaPlugin
@@ -9,9 +15,13 @@ const llsLinariaSsrCollectPlugin = () => {
9
15
  async resolveId(id, from) {
10
16
  if (id.includes('@linaria-cache')) { cssIds.add(id) }
11
17
  },
18
+ flushStyles() {
19
+ const back = `<style id="linaria-ssr-collect-plugin">${[...cssIds].map(linariaPlugin.load).join('\n')}</style>`
20
+ // linaria plugin keeps cache. But we dont want to keep ids which have changed (updating a css component)
21
+ // css is removed from client anyway but still be accurate
22
+ cssIds.clear()
12
23
 
13
- collectSsrStyles() {
14
- return `<style>${[...cssIds].map(linariaPlugin.load).join('\n')}</style>`
24
+ return back
15
25
  }
16
26
  }
17
27
  }
@@ -1,7 +1,12 @@
1
1
  import VitePluginRequireTransform from 'vite-plugin-require-transform'
2
2
 
3
- // needed for viewer if siderefresh
3
+ /**
4
+ * Plugin using vite-plugin-require-transform, used to transform require syntax to import
5
+ * Needed when we use viewer in sideRefresh
6
+ * @returns the plugin with its transform method
7
+ */
4
8
  const llsSsrRequirePlugin = () => {
9
+ // Lazy loaded viewer modules that are using require syntax
5
10
  const fileRegex = /(?:(Audio|Recorder|Python|Video|QuestionRich|CodemirrorEditor|useLazyModule)\.jsx$|@lls_lls-code)/
6
11
  const back = VitePluginRequireTransform({ fileRegex })
7
12
  return {
@@ -19,4 +24,4 @@ const llsSsrRequirePlugin = () => {
19
24
  }
20
25
  }
21
26
 
22
- export default llsSsrRequirePlugin
27
+ export default llsSsrRequirePlugin
@@ -9,6 +9,7 @@ const pwd = process.cwd()
9
9
  */
10
10
  const llsSideRefreshMetaPlugin = ({ viewer: iViewer, superkit: iSuperkit, kit: iKit, utils: iUtils }) => {
11
11
  if (!iViewer && !iSuperkit && !iKit && !iUtils) { return { plugin: () => false, alias: {} } }
12
+ // eslint-disable-next-line no-console
12
13
  console.log('sideResfresh: ', [
13
14
  iViewer && 'viewer',
14
15
  iSuperkit && 'superkit',