@crombolo/transfer 0.45.0 → 0.46.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.
Files changed (2) hide show
  1. package/package.json +3 -3
  2. package/src/code.ts +34 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/transfer",
3
- "version": "0.45.0",
3
+ "version": "0.46.1",
4
4
  "description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Content transfer for crombolo: bundles of content moved between environments.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -28,7 +28,7 @@
28
28
  "access": "public"
29
29
  },
30
30
  "dependencies": {
31
- "@crombolo/core": "0.45.0",
32
- "@crombolo/data": "0.45.0"
31
+ "@crombolo/core": "0.46.1",
32
+ "@crombolo/data": "0.46.1"
33
33
  }
34
34
  }
package/src/code.ts CHANGED
@@ -41,6 +41,36 @@ export function isNeverCode(path: string): boolean {
41
41
  )
42
42
  }
43
43
 
44
+ /** The site folder a bundle installed from a file is kept in (story 245). */
45
+ export const LOCAL_BUNDLES_DIR = 'bundles'
46
+
47
+ /** `bundles/<name>-<version>.tgz`'s file name: `@acme/crm` 1.2.0 is `acme-crm-1.2.0.tgz`. */
48
+ export const localBundleFileName = (name: string, version: string): string =>
49
+ `${name.replace(/^@/, '').replace('/', '-')}-${version}.tgz`
50
+
51
+ /** The `bundles/` file a dependency's range names, as `./bundles/x.tgz` or `file:bundles/x.tgz`. */
52
+ export function localBundlePath(range: string | undefined): string | undefined {
53
+ const match = /^(?:file:)?(?:\.\/)?bundles\/([^/\\]+\.tgz)$/.exec(range ?? '')
54
+ return match ? `${LOCAL_BUNDLES_DIR}/${match[1]}` : undefined
55
+ }
56
+
57
+ /** Every `bundles/` file the site's `package.json` names among its dependencies. */
58
+ export function localBundlesNamed(siteDir: string): string[] {
59
+ const file = join(siteDir, 'package.json')
60
+ if (!existsSync(file)) return []
61
+ const json = JSON.parse(readFileSync(file, 'utf8')) as {
62
+ dependencies?: Record<string, string>
63
+ devDependencies?: Record<string, string>
64
+ }
65
+ const named = new Set<string>()
66
+ for (const ranges of [json.dependencies, json.devDependencies])
67
+ for (const range of Object.values(ranges ?? {})) {
68
+ const path = localBundlePath(range)
69
+ if (path) named.add(path)
70
+ }
71
+ return [...named].sort()
72
+ }
73
+
44
74
  /** `crombolo.code` in a site's `package.json`, or undefined when it names none. */
45
75
  export function codePatternsOf(siteDir: string): string[] | undefined {
46
76
  const file = join(siteDir, 'package.json')
@@ -76,6 +106,10 @@ export function selectCodeFiles(
76
106
  if (matched === 0) problems.push(`"${pattern}" matches no file the bundle can carry`)
77
107
  }
78
108
  for (const always of CODE_ALWAYS) if (existsSync(join(siteDir, always))) paths.add(always)
109
+ // A bundle installed from a file (story 245) goes where its lockfile entry does.
110
+ for (const bundle of localBundlesNamed(siteDir))
111
+ if (existsSync(join(siteDir, bundle))) paths.add(bundle)
112
+ else problems.push(`package.json names ${bundle}, which is not in the site`)
79
113
  if (!existsSync(join(siteDir, 'package.json'))) problems.push('the site has no package.json')
80
114
  if (!existsSync(join(siteDir, 'bun.lock')))
81
115
  problems.push('the site has no bun.lock, so its code could not be installed as it was tested')