@_linked/cli 1.37.0 → 1.39.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.
- package/CHANGELOG.md +14 -0
- package/lib/esm/cli-methods.d.ts +2 -1
- package/lib/esm/cli-methods.d.ts.map +1 -1
- package/lib/esm/cli-methods.js +225 -52
- package/lib/esm/cli-methods.js.map +1 -1
- package/lib/esm/cli.d.ts.map +1 -1
- package/lib/esm/cli.js +18 -5
- package/lib/esm/cli.js.map +1 -1
- package/lib/esm/commands/localize.d.ts +14 -0
- package/lib/esm/commands/localize.d.ts.map +1 -1
- package/lib/esm/commands/localize.js +39 -3
- package/lib/esm/commands/localize.js.map +1 -1
- package/lib/esm/lifecycle.d.ts +8 -1
- package/lib/esm/lifecycle.d.ts.map +1 -1
- package/lib/esm/lifecycle.js +41 -11
- package/lib/esm/lifecycle.js.map +1 -1
- package/lib/esm/utils/createPackageLocation.d.ts +76 -0
- package/lib/esm/utils/createPackageLocation.d.ts.map +1 -0
- package/lib/esm/utils/createPackageLocation.js +157 -0
- package/lib/esm/utils/createPackageLocation.js.map +1 -0
- package/lib/esm/utils/ontologyNamespace.d.ts +21 -0
- package/lib/esm/utils/ontologyNamespace.d.ts.map +1 -0
- package/lib/esm/utils/ontologyNamespace.js +30 -0
- package/lib/esm/utils/ontologyNamespace.js.map +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.39.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#199](https://github.com/linked-fw/cli/pull/199) [`dfdb1c5`](https://github.com/linked-fw/cli/commit/dfdb1c50547bab428540db149afb4b106c9f0c5c) Thanks [@flyon](https://github.com/flyon)! - `create-package` chooses where a package lives inside an app: `packages/` (part of the app's repository: a workspace member, added to its dependencies and installed at the app root) or `packages-local/` (its own git repository, under `linked localize`'s name for it, with `git init`, a first commit, an optional `--remote` and `--push`, then installed, built, linked and recorded by `linked localize --adopt`). Choose with `--location`, `--remote` and `--push`; with none of them you are asked, on a terminal only. An existing target folder is refused. Outside an app nothing changes.
|
|
8
|
+
|
|
9
|
+
`linked localize --adopt` links a checkout already in `packages-local/` without cloning it, and `build-all` builds packages recorded in `local-packages.json` even when the app does not declare them yet. Needs `@_linked/localize` 0.2.0.
|
|
10
|
+
|
|
11
|
+
## 1.38.0
|
|
12
|
+
|
|
13
|
+
### Minor Changes
|
|
14
|
+
|
|
15
|
+
- [#202](https://github.com/linked-fw/cli/pull/202) [`a05333d`](https://github.com/linked-fw/cli/commit/a05333d7e3bc6b69878e07608eb5165d49437635) Thanks [@flyon](https://github.com/flyon)! - `create-package` and `create-ontology` scaffold new ontologies at `https://linked.cm/ont/{slug}/` instead of the legacy `http://lincd.org/ont/{name}/`, matching the first-party packages (arch-02). The slug is derived the way core derives a package's publicSlug: the npm scope is dropped and the rest kebab-cased, so `linked create-package @_linked/foo` now gets `https://linked.cm/ont/foo/` (it used to get `http://lincd.org/ont/@_linked/foo/`). An explicit `uri_base` argument still wins, which is how a private package gets its workspace-scoped root (`https://{workspaceSlug}.id.create.now/ont/{slug}/`); a `uri_base` that already ends in `/` or `#` is no longer given a second `/`.
|
|
16
|
+
|
|
3
17
|
## 1.37.0
|
|
4
18
|
|
|
5
19
|
### Minor Changes
|
package/lib/esm/cli-methods.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { CreatePackageOptions } from './utils/createPackageLocation.js';
|
|
1
2
|
import type { PackageDetails } from './interfaces.js';
|
|
2
3
|
/**
|
|
3
4
|
* Dynamically import the app's backend storage configuration. Tries the
|
|
@@ -130,7 +131,7 @@ export declare const startServer: (initOnly?: boolean, ServerClass?: any) => Pro
|
|
|
130
131
|
*/
|
|
131
132
|
export declare const buildBackend: () => Promise<boolean>;
|
|
132
133
|
export declare const upgradePackages: () => Promise<void>;
|
|
133
|
-
export declare const createPackage: (name: any, uriBase?: any, basePath?: string) => Promise<void>;
|
|
134
|
+
export declare const createPackage: (name: any, uriBase?: any, basePath?: string, options?: CreatePackageOptions) => Promise<void>;
|
|
134
135
|
export declare const register: (registryURL: any) => Promise<void>;
|
|
135
136
|
export declare const buildPackage: (target: any, target2: any, packagePath?: string, logResults?: boolean) => Promise<boolean>;
|
|
136
137
|
type BuildStep = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli-methods.d.ts","sourceRoot":"","sources":["../../src/cli-methods.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"cli-methods.d.ts","sourceRoot":"","sources":["../../src/cli-methods.ts"],"names":[],"mappings":"AA+BA,OAAO,KAAK,EACV,oBAAoB,EAErB,MAAM,kCAAkC,CAAC;AAmB1C,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,iBAAiB,CAAC;AAgBpD;;;;;;GAMG;AAKH,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,EACb,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,uBAAuB,EACvB,wBAAwB,EACxB,gBAAgB,EAChB,qBAAqB,EACrB,YAAY,GACb,CAAC;AAoBF,MAAM,MAAM,WAAW,GAAG,KAAK,GAAG,cAAc,CAAC;AAEjD,KAAK,WAAW,GAAG;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,eAAO,MAAM,SAAS,GAAU,SAAI,EAAE,iBAAwB,EAAE,UAAS;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAC;IAAC,QAAQ,CAAC,EAAE,WAAW,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AAa,aAAQ,EAAE,YAAO,SAMtD,CAAC;AACF,eAAO,IAAI,YAAY,GAAmB,iBAAwB,kBA8FjE,CAAC;AAEF,eAAO,IAAI,wBAAwB,GAAa,gBAAW,EAAE,YAAO,SAsCnE,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,cAAc,GAAU,gBAAW,qBA8B/C,CAAC"}
|
package/lib/esm/cli-methods.js
CHANGED
|
@@ -17,12 +17,13 @@ import { createInterface } from 'readline';
|
|
|
17
17
|
import { debugInfo, execp, execPromise, getFileImports, getFiles, getLastCommitTime, getPackageJSON, isImportOutsideOfPackage, isInternalLinkedImport, needsRebuilding, } from './utils.js';
|
|
18
18
|
import { renameShippedDotfiles } from './utils/shippedDotfiles.js';
|
|
19
19
|
import { planPackageSetup } from './utils/packageSetup.js';
|
|
20
|
+
import { bareName, CreatePackageError, decideCreatePackageTarget, ensureRelinkPostinstall, ensureWorkspaceGlob, findLinkedAppRoot, RELINK_COMMAND, repositoryUrlFor, } from './utils/createPackageLocation.js';
|
|
20
21
|
import { detectPackageManager, execBinCommand, runScriptCommand, } from './utils/packageManager.js';
|
|
21
22
|
import { rewriteExtensionlessImports } from './utils/esmSpecifiers.js';
|
|
22
23
|
import { checkShapeNames } from './utils/shapeNames.js';
|
|
23
24
|
import { checkShapeReferences, inspectShapeReferences, } from './utils/shapeReferences.js';
|
|
24
25
|
import { checkShapesIndex, checkShapesSideEffects } from './utils/shapesIndex.js';
|
|
25
|
-
import { spawn as spawnChild } from 'child_process';
|
|
26
|
+
import { spawn as spawnChild, spawnSync } from 'child_process';
|
|
26
27
|
import { findNearestPackageJson } from 'find-nearest-package-json';
|
|
27
28
|
import { statSync } from 'fs';
|
|
28
29
|
// import pkg from 'lincd/utils/LinkedFileStorage';
|
|
@@ -31,6 +32,7 @@ import { glob } from 'glob';
|
|
|
31
32
|
import ora from 'ora';
|
|
32
33
|
import stagedGitFiles from 'staged-git-files';
|
|
33
34
|
import { packagePublishesCjs } from './package-manifest.js';
|
|
35
|
+
import { asNamespace, defaultOntologyNamespace } from './utils/ontologyNamespace.js';
|
|
34
36
|
let dirname__ = typeof __dirname !== 'undefined'
|
|
35
37
|
? __dirname
|
|
36
38
|
: //@ts-ignore
|
|
@@ -1043,9 +1045,9 @@ export const createOntology = (prefix_1, uriBase_1, ...args_1) => __awaiter(void
|
|
|
1043
1045
|
let sourceFolder = getSourceFolder(basePath);
|
|
1044
1046
|
let targetFolder = ensureFolderExists(sourceFolder, 'ontologies');
|
|
1045
1047
|
if (!uriBase) {
|
|
1046
|
-
uriBase =
|
|
1048
|
+
uriBase = defaultOntologyNamespace(prefix);
|
|
1047
1049
|
}
|
|
1048
|
-
setVariable('uri_base', uriBase);
|
|
1050
|
+
setVariable('uri_base', asNamespace(uriBase));
|
|
1049
1051
|
let { hyphenName, camelCaseName, underscoreName } = setNameVariables(prefix);
|
|
1050
1052
|
//copy ontology accessor file
|
|
1051
1053
|
log("Creating files for ontology '" + prefix + "'");
|
|
@@ -1832,45 +1834,64 @@ export const upgradePackages = () => __awaiter(void 0, void 0, void 0, function*
|
|
|
1832
1834
|
// })
|
|
1833
1835
|
// });
|
|
1834
1836
|
});
|
|
1835
|
-
export const createPackage = (name_1, uriBase_1, ...args_1) => __awaiter(void 0, [name_1, uriBase_1, ...args_1], void 0, function* (name, uriBase, basePath = process.cwd()) {
|
|
1837
|
+
export const createPackage = (name_1, uriBase_1, ...args_1) => __awaiter(void 0, [name_1, uriBase_1, ...args_1], void 0, function* (name, uriBase, basePath = process.cwd(), options = {}) {
|
|
1836
1838
|
if (!name) {
|
|
1837
1839
|
console.warn('Please provide a name as the first argument');
|
|
1838
1840
|
return;
|
|
1839
1841
|
}
|
|
1840
|
-
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1842
|
+
const appRoot = findLinkedAppRoot(basePath);
|
|
1843
|
+
const decided = decideCreatePackageTarget({
|
|
1844
|
+
appRoot,
|
|
1845
|
+
options,
|
|
1846
|
+
isTTY: !!(process.stdin.isTTY && process.stdout.isTTY),
|
|
1847
|
+
});
|
|
1848
|
+
if (decided.kind === 'refuse')
|
|
1849
|
+
throw new CreatePackageError(decided.message);
|
|
1850
|
+
const decision = decided.kind === 'ask' ? yield askPackageLocation(name) : decided;
|
|
1851
|
+
//let's remove scope for variable names
|
|
1852
|
+
const cleanPackageName = bareName(name);
|
|
1853
|
+
let targetFolder;
|
|
1854
|
+
if (decision.kind === 'outside') {
|
|
1855
|
+
//if ran with npx, basePath will be the root directory of the repository, even if we're executing from a sub folder (the root directory is where node_modules lives and package.json with workspaces)
|
|
1856
|
+
//so we manually find a packages folder, if it exists we go into that.
|
|
1857
|
+
if (fs.existsSync(path.join(basePath, 'packages'))) {
|
|
1858
|
+
basePath = path.join(basePath, 'packages');
|
|
1859
|
+
}
|
|
1860
|
+
//for lincd.org currently packages are stored in the modules folder
|
|
1861
|
+
else if (fs.existsSync(path.join(basePath, 'modules'))) {
|
|
1862
|
+
basePath = path.join(basePath, 'modules');
|
|
1863
|
+
}
|
|
1864
|
+
targetFolder = path.join(basePath, cleanPackageName);
|
|
1844
1865
|
}
|
|
1845
|
-
|
|
1846
|
-
|
|
1847
|
-
|
|
1866
|
+
else if (decision.location === 'packages') {
|
|
1867
|
+
targetFolder = path.join(appRoot, 'packages', cleanPackageName);
|
|
1868
|
+
}
|
|
1869
|
+
else {
|
|
1870
|
+
// localize's own naming, so `linked localize` and this command can never
|
|
1871
|
+
// disagree about where a package lives.
|
|
1872
|
+
const { checkoutNameFor, DEFAULT_DIR } = yield import('@_linked/localize');
|
|
1873
|
+
targetFolder = path.join(appRoot, DEFAULT_DIR, checkoutNameFor(name));
|
|
1874
|
+
}
|
|
1875
|
+
if (fs.existsSync(targetFolder)) {
|
|
1876
|
+
throw new CreatePackageError(`${targetFolder} already exists. Refusing to write a new package over it.`);
|
|
1848
1877
|
}
|
|
1849
|
-
//let's remove scope for variable names
|
|
1850
|
-
let [packageName, scope, cleanPackageName] = name.match(/(@[\w\-]+\/)?([\w\-]+)/);
|
|
1851
|
-
let targetFolder = ensureFolderExists(basePath, cleanPackageName);
|
|
1852
1878
|
if (!uriBase) {
|
|
1853
|
-
uriBase =
|
|
1854
|
-
}
|
|
1855
|
-
setVariable('uri_base', uriBase
|
|
1856
|
-
//
|
|
1857
|
-
//so @dacore/some-mod/lib/file.js
|
|
1858
|
-
// --> match[0] = @dacore/some-mod
|
|
1859
|
-
// --> match[1] = @dacore
|
|
1860
|
-
// --> match[2] = some-mod
|
|
1861
|
-
//but save full scoped package name under ${package_name}
|
|
1879
|
+
uriBase = defaultOntologyNamespace(name);
|
|
1880
|
+
}
|
|
1881
|
+
setVariable('uri_base', asNamespace(uriBase));
|
|
1882
|
+
//save the full scoped package name under ${package_name}
|
|
1862
1883
|
setVariable('package_name', name);
|
|
1863
1884
|
//extra variable for clarity (will be same as 'name')
|
|
1864
1885
|
setVariable('output_file_name', name);
|
|
1865
|
-
|
|
1886
|
+
const { hyphenName } = setNameVariables(cleanPackageName);
|
|
1866
1887
|
log("Creating new linked package '" + name + "'");
|
|
1888
|
+
fs.mkdirSync(targetFolder, { recursive: true });
|
|
1867
1889
|
fs.copySync(path.join(getScriptDir(), '..', '..', 'defaults', 'package'), targetFolder);
|
|
1868
1890
|
renameShippedDotfiles(targetFolder);
|
|
1869
1891
|
//replace variables in some of the copied files
|
|
1870
1892
|
yield Promise.all([
|
|
1871
1893
|
'src/index.ts',
|
|
1872
1894
|
'package.json',
|
|
1873
|
-
'Gruntfile.js',
|
|
1874
1895
|
'src/package.ts',
|
|
1875
1896
|
'src/ontologies/example-ontology.ts',
|
|
1876
1897
|
'src/ontologies/example-ontology.register.ts',
|
|
@@ -1897,37 +1918,189 @@ export const createPackage = (name_1, uriBase_1, ...args_1) => __awaiter(void 0,
|
|
|
1897
1918
|
console.log('rename ', path.join(targetFolder, f), path.join(targetFolder, ...newParts, newName));
|
|
1898
1919
|
fs.renameSync(path.join(targetFolder, f), path.join(targetFolder, ...newParts, newName));
|
|
1899
1920
|
});
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1921
|
+
if (decision.kind === 'outside') {
|
|
1922
|
+
yield installStandalonePackage(targetFolder);
|
|
1923
|
+
}
|
|
1924
|
+
else if (decision.location === 'packages') {
|
|
1925
|
+
yield installWorkspacePackage(name, targetFolder, appRoot);
|
|
1926
|
+
}
|
|
1927
|
+
else {
|
|
1928
|
+
yield installOwnRepoPackage(name, targetFolder, appRoot, decision);
|
|
1929
|
+
}
|
|
1930
|
+
});
|
|
1931
|
+
/**
|
|
1932
|
+
* Ask where a new package goes — only ever on a terminal, and only when no
|
|
1933
|
+
* flag said so already.
|
|
1934
|
+
*/
|
|
1935
|
+
function askPackageLocation(name) {
|
|
1936
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1937
|
+
console.log(`\nWhere should ${chalk.magenta(name)} live?\n` +
|
|
1938
|
+
` 1) packages/ part of this app's repository\n` +
|
|
1939
|
+
` 2) packages-local/ its own git repository, linked into this app\n`);
|
|
1940
|
+
let answer = '';
|
|
1941
|
+
while (answer !== '1' && answer !== '2') {
|
|
1942
|
+
answer = yield promptUser('Choose 1 or 2: ');
|
|
1943
|
+
}
|
|
1944
|
+
if (answer === '1')
|
|
1945
|
+
return { kind: 'resolved', location: 'packages', push: false };
|
|
1946
|
+
const remote = yield promptUser('Remote git URL for its repository (optional, Enter to skip): ');
|
|
1947
|
+
const push = !!remote &&
|
|
1948
|
+
/^y(es)?$/i.test(yield promptUser(`Push the first commit to ${remote}? (y/N): `));
|
|
1949
|
+
return Object.assign(Object.assign({ kind: 'resolved', location: 'packages-local' }, (remote ? { remote } : {})), { push });
|
|
1950
|
+
});
|
|
1951
|
+
}
|
|
1952
|
+
/** The install + first build plan for a package, given where it installs from. */
|
|
1953
|
+
function packageSetupFor(installRoot) {
|
|
1954
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1955
|
+
// npm is the default for a new package. yarn is only consulted when the new
|
|
1956
|
+
// package lands inside an existing yarn project (a yarn-3 monorepo),
|
|
1957
|
+
// where adding an npm lockfile would break the workspace.
|
|
1958
|
+
const insideYarnProject = detectPackageManager(installRoot) === 'yarn';
|
|
1959
|
+
let version = insideYarnProject
|
|
1960
|
+
? (yield execPromise('yarn --version').catch(() => {
|
|
1961
|
+
console.log('yarn probably not working');
|
|
1962
|
+
return '';
|
|
1963
|
+
}))
|
|
1964
|
+
: '';
|
|
1965
|
+
return planPackageSetup(version.toString(), path.join(getScriptDir(), 'launch.js'), process.execPath, insideYarnProject);
|
|
1922
1966
|
});
|
|
1923
|
-
|
|
1924
|
-
|
|
1925
|
-
|
|
1967
|
+
}
|
|
1968
|
+
/**
|
|
1969
|
+
* Install `cwd` with `setup`, then build `targetFolder`. Failures set the exit
|
|
1970
|
+
* code; `installFailedHint` says what was already changed when the install fails.
|
|
1971
|
+
*/
|
|
1972
|
+
function installThenBuild(setup_1, cwd_1, targetFolder_1) {
|
|
1973
|
+
return __awaiter(this, arguments, void 0, function* (setup, cwd, targetFolder, installFailedHint = '') {
|
|
1974
|
+
const installed = yield execp(setup.installCommand, true, false, { cwd })
|
|
1975
|
+
.then(() => true)
|
|
1976
|
+
.catch(() => {
|
|
1977
|
+
console.warn(`Could not install dependencies (${setup.installCommand})` +
|
|
1978
|
+
(installFailedHint ? `. ${installFailedHint}` : ''));
|
|
1926
1979
|
process.exitCode = 1;
|
|
1980
|
+
return false;
|
|
1927
1981
|
});
|
|
1982
|
+
if (installed) {
|
|
1983
|
+
yield execp(setup.buildCommand, true, false, { cwd: targetFolder }).catch(() => {
|
|
1984
|
+
console.warn('Dependencies installed, but the initial build failed');
|
|
1985
|
+
process.exitCode = 1;
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
});
|
|
1989
|
+
}
|
|
1990
|
+
/** Outside an app: install inside the package itself, as this command always has. */
|
|
1991
|
+
function installStandalonePackage(targetFolder) {
|
|
1992
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
1993
|
+
const setup = yield packageSetupFor(path.dirname(path.resolve(targetFolder)));
|
|
1994
|
+
if (setup.yarnrc) {
|
|
1995
|
+
fs.writeFileSync(path.join(targetFolder, '.yarnrc.yml'), setup.yarnrc);
|
|
1996
|
+
}
|
|
1997
|
+
yield installThenBuild(setup, targetFolder, targetFolder);
|
|
1998
|
+
log(`Prepared a new linked package in ${chalk.magenta(targetFolder)}`, `Run ${chalk.blueBright(runScriptCommand(setup.packageManager, 'build'))} from this directory to build once`, `Or ${chalk.blueBright(runScriptCommand(setup.packageManager, 'start'))} to continuously rebuild on file changes`);
|
|
1999
|
+
});
|
|
2000
|
+
}
|
|
2001
|
+
/**
|
|
2002
|
+
* packages/: a workspace member of the app's own repository. The app's
|
|
2003
|
+
* workspaces must cover it and its dependencies declare it — npm links a
|
|
2004
|
+
* workspace member by name, and `build-all` builds what the app depends on —
|
|
2005
|
+
* and the install runs at the app root, where the workspace is.
|
|
2006
|
+
*/
|
|
2007
|
+
function installWorkspacePackage(name, targetFolder, appRoot) {
|
|
2008
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2009
|
+
const appPkgPath = path.join(appRoot, 'package.json');
|
|
2010
|
+
const appPkg = fs.readJsonSync(appPkgPath);
|
|
2011
|
+
const workspaces = ensureWorkspaceGlob(appPkg);
|
|
2012
|
+
if (workspaces.warning)
|
|
2013
|
+
console.warn(chalk.yellow(workspaces.warning));
|
|
2014
|
+
const version = fs.readJsonSync(path.join(targetFolder, 'package.json')).version;
|
|
2015
|
+
appPkg.dependencies = Object.assign(Object.assign({}, appPkg.dependencies), { [name]: `^${version}` });
|
|
2016
|
+
fs.writeJsonSync(appPkgPath, appPkg, { spaces: 2 });
|
|
2017
|
+
log(`Added ${name}@^${version} to ${path.relative(process.cwd(), appPkgPath) || 'package.json'}` +
|
|
2018
|
+
(workspaces.changed ? ' and packages/* to its workspaces' : ''));
|
|
2019
|
+
const setup = yield packageSetupFor(appRoot);
|
|
2020
|
+
yield installThenBuild(setup, appRoot, targetFolder, `The app's package.json already declares ${name}; run the install again at the app root once it is fixed.`);
|
|
2021
|
+
log(`Prepared a new linked package in ${chalk.magenta(targetFolder)}, part of this app's repository`, `Run ${chalk.blueBright(runScriptCommand(setup.packageManager, 'start'))} in it to continuously rebuild on file changes`);
|
|
2022
|
+
});
|
|
2023
|
+
}
|
|
2024
|
+
/**
|
|
2025
|
+
* packages-local/: a repository of its own. Its git history starts here, and
|
|
2026
|
+
* localize's `adopt` installs, builds, links and records it. The app's
|
|
2027
|
+
* dependencies are NOT touched: until the package is published a version range
|
|
2028
|
+
* fails `npm install` (E404 once a lockfile exists), and a `file:` path would
|
|
2029
|
+
* install cleanly for a teammate without the checkout and fail at runtime.
|
|
2030
|
+
*/
|
|
2031
|
+
function installOwnRepoPackage(name, targetFolder, appRoot, decision) {
|
|
2032
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
2033
|
+
const { remote, push } = decision;
|
|
2034
|
+
const rel = path.relative(appRoot, targetFolder);
|
|
2035
|
+
const pkgPath = path.join(targetFolder, 'package.json');
|
|
2036
|
+
const fail = (message) => {
|
|
2037
|
+
console.warn(chalk.yellow(message));
|
|
2038
|
+
process.exitCode = 1;
|
|
2039
|
+
};
|
|
2040
|
+
if (!git(['init', '--quiet'], targetFolder)) {
|
|
2041
|
+
return fail(`git init failed in ${rel}; the package is scaffolded but not linked.`);
|
|
2042
|
+
}
|
|
2043
|
+
if (remote) {
|
|
2044
|
+
if (!git(['remote', 'add', 'origin', remote], targetFolder)) {
|
|
2045
|
+
return fail(`git remote add origin ${remote} failed in ${rel}; nothing was linked.`);
|
|
2046
|
+
}
|
|
2047
|
+
const pkg = fs.readJsonSync(pkgPath);
|
|
2048
|
+
pkg.repository = { type: 'git', url: repositoryUrlFor(remote) };
|
|
2049
|
+
fs.writeJsonSync(pkgPath, pkg, { spaces: 2 });
|
|
2050
|
+
}
|
|
2051
|
+
// Before adopt, never during it: adopt asserts the app's package.json did not
|
|
2052
|
+
// change while it ran.
|
|
2053
|
+
const appPkgPath = path.join(appRoot, 'package.json');
|
|
2054
|
+
const appPkg = fs.readJsonSync(appPkgPath);
|
|
2055
|
+
if (ensureRelinkPostinstall(appPkg)) {
|
|
2056
|
+
fs.writeJsonSync(appPkgPath, appPkg, { spaces: 2 });
|
|
2057
|
+
log(`Added \`${RELINK_COMMAND}\` to the app's postinstall, so npm install keeps the link`);
|
|
2058
|
+
}
|
|
2059
|
+
const { adoptPackage } = yield import('./commands/localize.js');
|
|
2060
|
+
const { EXIT_WARNED } = yield import('@_linked/localize');
|
|
2061
|
+
// Only the build command matters here: adopt always installs with npm, so
|
|
2062
|
+
// the package-manager half of the plan does not apply.
|
|
2063
|
+
const { buildCommand } = planPackageSetup('', path.join(getScriptDir(), 'launch.js'), process.execPath);
|
|
2064
|
+
const code = yield adoptPackage(name, { appRoot, build: buildCommand });
|
|
2065
|
+
if (code === EXIT_WARNED) {
|
|
2066
|
+
fail('The package is linked, but its initial build failed');
|
|
2067
|
+
}
|
|
2068
|
+
else if (code !== 0) {
|
|
2069
|
+
return fail(`Linking ${name} failed (localize exit ${code}). ${rel} is scaffolded with an uncommitted ` +
|
|
2070
|
+
`git init, and the app's postinstall relinks localized packages. Fix the cause and retry ` +
|
|
2071
|
+
`with: linked localize ${name} --adopt`);
|
|
2072
|
+
}
|
|
2073
|
+
const committed = git(['add', '-A'], targetFolder) &&
|
|
2074
|
+
git(['commit', '--quiet', '-m', `feat: scaffold ${name}`], targetFolder);
|
|
2075
|
+
if (!committed) {
|
|
2076
|
+
fail(`Could not make the first commit in ${rel} (is git's user.name/user.email set?). ` +
|
|
2077
|
+
`The package is linked; commit it yourself.`);
|
|
2078
|
+
}
|
|
2079
|
+
let pushed = false;
|
|
2080
|
+
if (push && committed) {
|
|
2081
|
+
pushed = git(['push', '--quiet', '-u', 'origin', 'HEAD'], targetFolder);
|
|
2082
|
+
if (!pushed)
|
|
2083
|
+
fail(`Could not push to ${remote}. Push it yourself: git push -u origin HEAD`);
|
|
2084
|
+
}
|
|
2085
|
+
const version = fs.readJsonSync(pkgPath).version;
|
|
2086
|
+
log(`Prepared ${name} in ${chalk.magenta(rel)}, in its own git repository` +
|
|
2087
|
+
(remote ? ` (origin ${remote}${pushed ? ', pushed' : ''})` : ' (no remote yet)'), `It is linked into node_modules and recorded in local-packages.json.`, `It is not in the app's dependencies: until it is published a version range would fail npm install.`, ` After publishing: ${chalk.blueBright(`npm install ${name}@^${version}`)}`);
|
|
2088
|
+
if (!remote) {
|
|
2089
|
+
log(`To add a remote later: ${chalk.blueBright('git remote add origin <url>')} in ${rel}, ` +
|
|
2090
|
+
`then ${chalk.blueBright(`linked localize ${name} --adopt`)} to record it.`);
|
|
2091
|
+
}
|
|
2092
|
+
});
|
|
2093
|
+
}
|
|
2094
|
+
/** Run git with arguments (no shell, so a URL is never re-parsed). Echoes failures. */
|
|
2095
|
+
function git(args, cwd) {
|
|
2096
|
+
var _a;
|
|
2097
|
+
const r = spawnSync('git', args, { cwd, encoding: 'utf8' });
|
|
2098
|
+
if (r.status !== 0) {
|
|
2099
|
+
console.warn((r.stderr || r.stdout || String((_a = r.error) !== null && _a !== void 0 ? _a : '')).trim());
|
|
2100
|
+
return false;
|
|
1928
2101
|
}
|
|
1929
|
-
|
|
1930
|
-
}
|
|
2102
|
+
return true;
|
|
2103
|
+
}
|
|
1931
2104
|
var getNextVersion = function (version) {
|
|
1932
2105
|
let parts = version.split('.');
|
|
1933
2106
|
return parts[0] + '.' + parts[1] + '.' + (parseInt(parts[2]) + 1).toString();
|