@voxgig/sdkgen-infrapack 0.0.6 → 0.0.7

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.
@@ -65,20 +65,32 @@ main: kit: target: 'seneca-provider': {
65
65
  # `repo` defaults to the SDK's own repository, so normally only the ref is
66
66
  # stated.
67
67
  #
68
- # `path` is the SUBDIRECTORY the SDK package sits in, because npm resolves
69
- # a git dependency against the repository root and sdkgen generates the
70
- # TypeScript SDK into `ts/`. It therefore defaults to `ts` — the layout
71
- # this toolchain produces — and npm spells it `#<ref>::path:<path>`. Set it
72
- # to `.` for an SDK whose package.json IS the repository root.
68
+ # WHICH KIND TO USE DEPENDS ON WHERE THE PACKAGE SITS. npm resolves a git
69
+ # dependency against the repository ROOT, and sdkgen generates the
70
+ # TypeScript SDK into `ts/` — so `git` suits an SDK that IS its repository
71
+ # root, and `release` suits this toolchain's own layout:
72
+ #
73
+ # kind: 'git' github:owner/repo#<ref>
74
+ # kind: 'release' https://github.com/owner/repo/releases/download/
75
+ # <ref>/<asset>.tgz
76
+ #
77
+ # A release asset is `npm pack` output attached to the tag; npm installs an
78
+ # https tarball natively and never looks at the repository layout. `asset`
79
+ # names the file when it is not the usual `<scope>-<name>-<version>.tgz`.
80
+ #
81
+ # There is no subdirectory option, deliberately. npm's spec parser accepts
82
+ # `#<ref>::path:ts` and reports a gitSubdir, so it reads as supported — but
83
+ # the INSTALLER ignores it and fails with ENOENT, on linux, macOS and
84
+ # Windows alike. A knob that produces an uninstallable dependency is worse
85
+ # than no knob.
73
86
  #
74
87
  # `spec` states the whole dependency value outright and wins over
75
- # everything, for anything the shorthand cannot express — a release-tarball
76
- # URL, say.
88
+ # everything.
77
89
  sdk: dep: {
78
- kind: *'npm' | 'git'
90
+ kind: *'npm' | 'git' | 'release'
79
91
  ref: *'' | string
80
92
  repo: *'' | string
81
- path: *'ts' | string
93
+ asset: *'' | string
82
94
  spec: *'' | string
83
95
  }
84
96
 
@@ -708,14 +708,21 @@ const Main = cmp(function Main(props: any) {
708
708
  // into every generated provider's CI.
709
709
  const liveApp = true === live.app || (loopback(specBase) && '' === (live.base || ''))
710
710
 
711
+ const sdkDep = sdkDependency(model, target, {
712
+ sdkPkg, sdkVersion, sdkRepoUrl: repoInfo(model).repoUrl,
713
+ })
714
+
711
715
  const provider = {
712
716
  Name, lower, ENV, sdkClass, pluginName, fileBase,
713
717
  sdkPkg, sdkVersion, entities,
714
- // Whether the SDK dependency is a git tag rather than a registry
715
- // package. The generated CI note says which, because "npm install is all
716
- // you need" stops being true the moment git is in the path.
717
- sdkGit: sdkDependency(model, target, { sdkVersion, sdkRepoUrl: repoInfo(model).repoUrl })
718
- .startsWith('github:'),
718
+ // The SDK dependency, resolved ONCE. PackageJson emits it and the CI
719
+ // note describes it, and computing it twice is how the second caller
720
+ // came to pass a half-built provider object into it.
721
+ sdkDep,
722
+ // Whether that dependency comes from outside a registry. The generated
723
+ // CI note says so, because "npm install is all you need" stops being
724
+ // true the moment git or a tarball URL is in the path.
725
+ sdkGit: !sdkDep.startsWith('^'),
719
726
  repoUrl: repo.url,
720
727
  // The SDK's own repo, for pointing at the companion test server which is
721
728
  // only distributed in source.
@@ -790,13 +797,21 @@ const Main = cmp(function Main(props: any) {
790
797
  // `kind: 'git'` points at a GIT TAG instead, which needs no registry.
791
798
  //
792
799
  // NPM RESOLVES A GIT DEPENDENCY AGAINST THE REPOSITORY ROOT, and sdkgen
793
- // generates the TypeScript SDK into `ts/` — so the bare
794
- // `github:owner/repo#ref` every example shows would install a directory with
795
- // no package.json in it. npm spells the subdirectory `#<ref>::path:<sub>`
796
- // (npm-package-arg resolves that to gitSubdir), and `path` therefore
797
- // defaults to `ts` rather than to nothing: the default has to match the
798
- // layout this toolchain actually produces, or the shorthand is a trap. `.`
799
- // means the package IS the repository root.
800
+ // generates the TypeScript SDK into `ts/`. So `kind: 'git'` suits an SDK
801
+ // whose package.json IS the repository root, and NOT the layout this
802
+ // toolchain produces.
803
+ //
804
+ // THE `::path:` SUBDIRECTORY SYNTAX DOES NOT WORK, and it looks like it
805
+ // does. npm-package-arg parses `#<ref>::path:ts` and reports
806
+ // `gitSubdir: /ts`, so a spec built that way reads as correct — but the
807
+ // INSTALLER ignores it: npm clones the repository and opens package.json at
808
+ // the clone root, failing with ENOENT on linux, macOS and Windows alike.
809
+ // That was measured, on all three, after the parser had said otherwise.
810
+ //
811
+ // `kind: 'release'` is the form that works for a package in a subdirectory:
812
+ // a GitHub release asset, which is `npm pack` output attached to the tag.
813
+ // npm installs an https tarball natively and never looks at the repository
814
+ // layout at all.
800
815
  //
801
816
  // `spec` still wins over all of it, for anything the shorthand cannot say.
802
817
  function sdkDependency(model: any, target: any, provider: any): string {
@@ -807,7 +822,8 @@ function sdkDependency(model: any, target: any, provider: any): string {
807
822
  return spec
808
823
  }
809
824
 
810
- if ('git' !== String(dep.kind || 'npm')) {
825
+ const kind = String(dep.kind || 'npm')
826
+ if ('git' !== kind && 'release' !== kind) {
811
827
  return `^${provider.sdkVersion}`
812
828
  }
813
829
 
@@ -837,11 +853,17 @@ function sdkDependency(model: any, target: any, provider: any): string {
837
853
  'on, e.g. `sdk.dep.ref: "v' + provider.sdkVersion + '"`.')
838
854
  }
839
855
 
840
- // `.` (and empty) mean the repository root, which needs no path segment.
841
- const sub = String(dep.path ?? 'ts').trim().replace(/^\/+|\/+$/g, '')
856
+ if ('release' === kind) {
857
+ // The asset `npm pack` produces: scope and name flattened, then the
858
+ // version. `asset` overrides it for a project that names its own.
859
+ const asset = String(dep.asset || '').trim() || (
860
+ provider.sdkPkg.replace(/^@/, '').replace(/\//g, '-') +
861
+ '-' + provider.sdkVersion + '.tgz')
862
+
863
+ return `https://github.com/${repo}/releases/download/${ref}/${asset}`
864
+ }
842
865
 
843
- return `github:${repo}#${ref}` +
844
- ('' === sub || '.' === sub ? '' : `::path:${sub}`)
866
+ return `github:${repo}#${ref}`
845
867
  }
846
868
 
847
869
 
@@ -948,7 +970,7 @@ const PackageJson = cmp(function PackageJson(props: any) {
948
970
  // The SDK this plugin wraps. Published-and-pinned by default; a git
949
971
  // tag when the project says so, because an unpublished SDK otherwise
950
972
  // leaves this package unable to install at all. See sdkDependency.
951
- [provider.sdkPkg]: sdkDependency(model, target, provider),
973
+ [provider.sdkPkg]: provider.sdkDep,
952
974
  ...dep('prod'),
953
975
  },
954
976
  peerDependencies: dep('peer'),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@voxgig/sdkgen-infrapack",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "Infrastructure-provider targets for the Voxgig SDK Generator: Seneca provider.",
5
5
  "type": "commonjs",
6
6
  "license": "MIT",
@@ -3,7 +3,7 @@
3
3
  "package": 1
4
4
  },
5
5
  "name": "@voxgig/sdkgen-infrapack",
6
- "version": "0.0.6",
6
+ "version": "0.0.7",
7
7
  "engines": {
8
8
  "sdkgen": ">=4.12.0"
9
9
  },