@poveste/plugin-vue 0.14.0 → 0.16.0

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.
Files changed (68) hide show
  1. package/README.md +2 -2
  2. package/components.d.ts +4 -0
  3. package/dist/bundled/client/app/MountStory.js +8 -3
  4. package/dist/bundled/client/app/RenderStory.js +15 -9
  5. package/dist/bundled/client/app/Story.js +76 -62
  6. package/dist/bundled/client/app/Variant.js +48 -42
  7. package/dist/bundled/client/app/context.js +5 -0
  8. package/dist/bundled/client/app/global-components.js +11 -10
  9. package/dist/bundled/client/app/host.js +2 -2
  10. package/dist/bundled/client/app/render-context.js +7 -7
  11. package/dist/bundled/client/app/util.js +36 -26
  12. package/dist/bundled/client/client.js +4 -4
  13. package/dist/bundled/client/codegen.js +79 -60
  14. package/dist/bundled/client/context.js +20 -0
  15. package/dist/bundled/client/server/Story.js +28 -25
  16. package/dist/bundled/client/server/Variant.js +13 -16
  17. package/dist/bundled/client/server/context.js +5 -0
  18. package/dist/bundled/client/server/run.js +29 -29
  19. package/dist/client/app/MountStory.d.ts +12 -3
  20. package/dist/client/app/RenderStory.d.ts +1 -1
  21. package/dist/client/app/Story.d.ts +10 -7
  22. package/dist/client/app/Variant.d.ts +14 -13
  23. package/dist/client/app/context.d.ts +9 -0
  24. package/dist/client/app/render-context.d.ts +16 -1
  25. package/dist/client/app/util.d.ts +38 -3
  26. package/dist/client/codegen.d.ts +29 -0
  27. package/dist/client/context.d.ts +40 -0
  28. package/dist/client/server/Story.d.ts +17 -17
  29. package/dist/client/server/Variant.d.ts +10 -10
  30. package/dist/client/server/context.d.ts +7 -0
  31. package/dist/commands/generate-story.client.js +4 -4
  32. package/dist/commands/generate-story.server.js +2 -2
  33. package/dist/helpers.d.ts +2 -2
  34. package/dist/index.node.js +2 -0
  35. package/dist/util/list-components.d.ts +1 -1
  36. package/dist/util/list-components.js +63 -6
  37. package/dist/util/list-components.spec.d.ts +1 -0
  38. package/dist/util/list-components.spec.js +46 -0
  39. package/package.json +17 -16
  40. package/src/client/__tests__/codegen-attrs.spec.ts +149 -0
  41. package/src/client/__tests__/context.spec.ts +50 -0
  42. package/src/client/app/MountStory.ts +11 -1
  43. package/src/client/app/RenderStory.ts +6 -1
  44. package/src/client/app/RouterLinkStub.ts +1 -1
  45. package/src/client/app/Story.ts +85 -39
  46. package/src/client/app/Variant.ts +35 -27
  47. package/src/client/app/__tests__/preview-variants.spec.ts +76 -0
  48. package/src/client/app/__tests__/state-sync.spec.ts +113 -2
  49. package/src/client/app/__tests__/writable-binding.spec.ts +39 -0
  50. package/src/client/app/auto-props.ts +2 -2
  51. package/src/client/app/context.ts +17 -0
  52. package/src/client/app/global-components.ts +20 -14
  53. package/src/client/app/host.ts +9 -6
  54. package/src/client/app/render-context.ts +25 -5
  55. package/src/client/app/util.ts +104 -9
  56. package/src/client/codegen.ts +81 -29
  57. package/src/client/context.ts +66 -0
  58. package/src/client/server/Story.ts +16 -10
  59. package/src/client/server/Variant.ts +13 -14
  60. package/src/client/server/__tests__/nesting-errors.spec.ts +48 -0
  61. package/src/client/server/context.ts +18 -0
  62. package/src/client/server/run.ts +11 -7
  63. package/src/commands/generate-story.client.ts +4 -4
  64. package/src/commands/generate-story.server.ts +2 -2
  65. package/src/helpers.ts +2 -2
  66. package/src/index.node.ts +2 -0
  67. package/src/util/list-components.spec.ts +54 -0
  68. package/src/util/list-components.ts +68 -6
@@ -1,13 +1,75 @@
1
- import { globby } from 'globby'
1
+ import { existsSync, readFileSync } from 'node:fs'
2
+ import { dirname, join, relative, resolve, sep } from 'node:path'
3
+ import ignore from 'ignore'
4
+ import { glob } from 'tinyglobby'
2
5
 
3
- export async function listComponentFiles(search = '', ignore: string[] = [], limit = 10) {
4
- let files = await globby('**/*.vue', {
5
- gitignore: true,
6
+ function toPosix(path: string): string {
7
+ return path.split(sep).join('/')
8
+ }
9
+
10
+ /**
11
+ * Whether a file under `cwd` is git-ignored, the way globby's `gitignore: true`
12
+ * decided it: every `.gitignore` from the repository root down, each pattern
13
+ * relative to its own file. tinyglobby reads none of them (#839).
14
+ */
15
+ async function gitIgnoredFilter(cwd: string): Promise<(file: string) => boolean> {
16
+ let root = cwd
17
+ while (!existsSync(join(root, '.git'))) {
18
+ const parent = dirname(root)
19
+ if (parent === root) {
20
+ root = cwd
21
+ break
22
+ }
23
+ root = parent
24
+ }
25
+
26
+ const ancestors: string[] = []
27
+ for (let dir = cwd; dir !== root;) {
28
+ dir = dirname(dir)
29
+ ancestors.unshift(join(dir, '.gitignore'))
30
+ }
31
+ // Shallow files first, so a nested `.gitignore` can override its parent.
32
+ const nested = (await glob('**/.gitignore', { cwd, absolute: true, dot: true, ignore: ['**/node_modules/**', '**/.git/**'] }))
33
+ .sort((a, b) => a.split('/').length - b.split('/').length || a.localeCompare(b))
34
+
35
+ const rules = ignore()
36
+ for (const file of [...ancestors, ...nested]) {
37
+ if (!existsSync(file)) {
38
+ continue
39
+ }
40
+ const base = toPosix(relative(root, dirname(file)))
41
+ for (const raw of readFileSync(file, 'utf8').split(/\r?\n/)) {
42
+ const line = raw.trimEnd()
43
+ if (!line || line.startsWith('#')) {
44
+ continue
45
+ }
46
+ const negated = line.startsWith('!')
47
+ let pattern = negated ? line.slice(1) : line
48
+ if (base) {
49
+ // A pattern with a slash before its end is anchored to its own directory;
50
+ // one without matches at any depth below it.
51
+ const anchored = pattern.replace(/\/$/, '').includes('/')
52
+ pattern = anchored ? `${base}/${pattern.replace(/^\//, '')}` : `${base}/**/${pattern}`
53
+ }
54
+ rules.add(negated ? `!${pattern}` : pattern)
55
+ }
56
+ }
57
+
58
+ return (file) => {
59
+ const path = toPosix(relative(root, resolve(cwd, file)))
60
+ return !path.startsWith('..') && rules.ignores(path)
61
+ }
62
+ }
63
+
64
+ export async function listComponentFiles(search = '', ignoredPatterns: string[] = [], limit = 10, cwd = process.cwd()) {
65
+ const isIgnored = await gitIgnoredFilter(cwd)
66
+ let files = (await glob('**/*.vue', {
67
+ cwd,
6
68
  ignore: [
7
69
  'node_modules',
8
- ...ignore,
70
+ ...ignoredPatterns,
9
71
  ],
10
- })
72
+ })).filter(file => !isIgnored(file))
11
73
  if (search) {
12
74
  const searchText = search.toLowerCase()
13
75
  files = files.filter(file => file.toLowerCase().includes(searchText))