@intlayer/engine 9.5.7 → 9.5.9-canary.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/dist/assets/installSkills/skills/angular.md +19 -68
- package/dist/assets/installSkills/skills/astro.md +38 -4
- package/dist/assets/installSkills/skills/backend.md +113 -0
- package/dist/assets/installSkills/skills/cli.md +29 -25
- package/dist/assets/installSkills/skills/compat.md +87 -0
- package/dist/assets/installSkills/skills/compiler.md +14 -4
- package/dist/assets/installSkills/skills/config.md +15 -5
- package/dist/assets/installSkills/skills/content.md +80 -6
- package/dist/assets/installSkills/skills/dev-tools.md +82 -0
- package/dist/assets/installSkills/skills/lit.md +115 -0
- package/dist/assets/installSkills/skills/markdown.md +96 -0
- package/dist/assets/installSkills/skills/next-js.md +21 -38
- package/dist/assets/installSkills/skills/preact.md +18 -0
- package/dist/assets/installSkills/skills/react.md +21 -4
- package/dist/assets/installSkills/skills/remix.md +95 -0
- package/dist/assets/installSkills/skills/remote-content.md +1 -1
- package/dist/assets/installSkills/skills/solid.md +21 -1
- package/dist/assets/installSkills/skills/svelte.md +22 -1
- package/dist/assets/installSkills/skills/usage.md +28 -0
- package/dist/assets/installSkills/skills/vanilla.md +108 -0
- package/dist/assets/installSkills/skills/vue.md +22 -0
- package/dist/cjs/_virtual/_utils_asset.cjs +1 -1
- package/dist/cjs/build.cjs +4 -4
- package/dist/cjs/buildIntlayerDictionary/writeDynamicDictionary.cjs +2 -2
- package/dist/cjs/buildIntlayerDictionary/writeFetchDictionary.cjs +3 -3
- package/dist/cjs/buildIntlayerDictionary/writeMergedDictionary.cjs +1 -1
- package/dist/cjs/buildIntlayerDictionary/writeNestedDictionary.cjs +3 -3
- package/dist/cjs/buildIntlayerDictionary/writeRemoteDictionary.cjs +2 -2
- package/dist/cjs/buildIntlayerDictionary/writeUnmergedDictionary.cjs +2 -2
- package/dist/cjs/cleanOutputDir.cjs +1 -1
- package/dist/cjs/cleanRemovedContentDeclaration.cjs +1 -1
- package/dist/cjs/cli.cjs +5 -3
- package/dist/cjs/createDictionaryEntryPoint/createDictionaryEntryPoint.cjs +1 -1
- package/dist/cjs/createDictionaryEntryPoint/getBuiltDictionariesPath.cjs +2 -2
- package/dist/cjs/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.cjs +2 -2
- package/dist/cjs/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.cjs +2 -2
- package/dist/cjs/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.cjs +2 -2
- package/dist/cjs/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.cjs +2 -2
- package/dist/cjs/createType/createModuleAugmentation.cjs +3 -3
- package/dist/cjs/createType/createType.cjs +1 -1
- package/dist/cjs/docReview/index.cjs +5 -5
- package/dist/cjs/docReview/pipeline.cjs +4 -4
- package/dist/cjs/fetchDistantDictionaries.cjs +1 -1
- package/dist/cjs/handleContentDeclarationFileChange.cjs +2 -2
- package/dist/cjs/handleUnlinkedContentDeclarationFile.cjs +1 -1
- package/dist/cjs/init/frameworkSetup/nextAppRouter/restructure.cjs +1 -1
- package/dist/cjs/init/frameworkSetup/tanstackStart/restructure.cjs +1 -1
- package/dist/cjs/init/index.cjs +305 -300
- package/dist/cjs/init/index.cjs.map +1 -1
- package/dist/cjs/init/upgradeIntlayerPackages.cjs +60 -0
- package/dist/cjs/init/upgradeIntlayerPackages.cjs.map +1 -0
- package/dist/cjs/init/utils/fileSystem.cjs +1 -1
- package/dist/cjs/init/utils/githubActions.cjs +1 -1
- package/dist/cjs/init/utils/index.cjs +13 -4
- package/dist/cjs/init/utils/intlayerDependencies.cjs +119 -0
- package/dist/cjs/init/utils/intlayerDependencies.cjs.map +1 -0
- package/dist/cjs/init/utils/packageManager.cjs +146 -95
- package/dist/cjs/init/utils/packageManager.cjs.map +1 -1
- package/dist/cjs/initConfig/index.cjs +1 -1
- package/dist/cjs/installLSP.cjs +1 -1
- package/dist/cjs/installMCP/installMCP.cjs +1 -1
- package/dist/cjs/installSkills/index.cjs +111 -20
- package/dist/cjs/installSkills/index.cjs.map +1 -1
- package/dist/cjs/listDictionariesPath.cjs +1 -1
- package/dist/cjs/listGitFiles.cjs +1 -1
- package/dist/cjs/loadDictionaries/getIntlayerBundle.cjs +2 -2
- package/dist/cjs/loadDictionaries/index.cjs +1 -1
- package/dist/cjs/loadDictionaries/loadContentDeclaration.cjs +2 -2
- package/dist/cjs/loadDictionaries/loadDictionaries.cjs +1 -1
- package/dist/cjs/loadDictionaries/loadLocalDictionaries.cjs +1 -1
- package/dist/cjs/loadDictionaries/loadMarkdownContentDeclaration.cjs +1 -1
- package/dist/cjs/logConfigDetails.cjs +1 -1
- package/dist/cjs/prepareIntlayer.cjs +4 -4
- package/dist/cjs/scan/index.cjs +1 -1
- package/dist/cjs/scan/scanWebsite.cjs +1 -1
- package/dist/cjs/syncPluginKit/createFileAdapter.cjs +1 -1
- package/dist/cjs/syncPluginKit/index.cjs +1 -1
- package/dist/cjs/utils/buildComponentFilesList.cjs +1 -1
- package/dist/cjs/utils/contentWatcherLock.cjs +2 -2
- package/dist/cjs/utils/index.cjs +4 -4
- package/dist/cjs/utils/readDictionariesFromDisk.cjs +1 -1
- package/dist/cjs/utils/runOnce.cjs +1 -1
- package/dist/cjs/utils/runParallel/pidTree.cjs +1 -1
- package/dist/cjs/utils/withFileLock.cjs +1 -1
- package/dist/cjs/watcher.cjs +6 -6
- package/dist/cjs/writeConfiguration/index.cjs +1 -1
- package/dist/cjs/writeContentDeclaration/processContentDeclarationContent.cjs +2 -2
- package/dist/cjs/writeContentDeclaration/transformJSFile.cjs +1 -1
- package/dist/cjs/writeContentDeclaration/writeContentDeclaration.cjs +4 -4
- package/dist/cjs/writeContentDeclaration/writeJSFile.cjs +3 -3
- package/dist/cjs/writeContentDeclaration/writeMarkdownFile.cjs +1 -1
- package/dist/cjs/writeContentDeclaration/writeYamlFile.cjs +1 -1
- package/dist/cjs/writeFileIfChanged.cjs +1 -1
- package/dist/esm/_virtual/_utils_asset.mjs +1 -1
- package/dist/esm/build.mjs +4 -4
- package/dist/esm/buildIntlayerDictionary/writeDynamicDictionary.mjs +2 -2
- package/dist/esm/buildIntlayerDictionary/writeFetchDictionary.mjs +3 -3
- package/dist/esm/buildIntlayerDictionary/writeMergedDictionary.mjs +1 -1
- package/dist/esm/buildIntlayerDictionary/writeNestedDictionary.mjs +3 -3
- package/dist/esm/buildIntlayerDictionary/writeRemoteDictionary.mjs +2 -2
- package/dist/esm/buildIntlayerDictionary/writeUnmergedDictionary.mjs +2 -2
- package/dist/esm/cleanOutputDir.mjs +1 -1
- package/dist/esm/cleanRemovedContentDeclaration.mjs +1 -1
- package/dist/esm/cli.mjs +5 -4
- package/dist/esm/createDictionaryEntryPoint/createDictionaryEntryPoint.mjs +1 -1
- package/dist/esm/createDictionaryEntryPoint/getBuiltDictionariesPath.mjs +2 -2
- package/dist/esm/createDictionaryEntryPoint/getBuiltDynamicDictionariesPath.mjs +2 -2
- package/dist/esm/createDictionaryEntryPoint/getBuiltFetchDictionariesPath.mjs +2 -2
- package/dist/esm/createDictionaryEntryPoint/getBuiltRemoteDictionariesPath.mjs +2 -2
- package/dist/esm/createDictionaryEntryPoint/getBuiltUnmergedDictionariesPath.mjs +2 -2
- package/dist/esm/createType/createModuleAugmentation.mjs +3 -3
- package/dist/esm/createType/createType.mjs +1 -1
- package/dist/esm/docReview/index.mjs +5 -5
- package/dist/esm/docReview/pipeline.mjs +4 -4
- package/dist/esm/fetchDistantDictionaries.mjs +1 -1
- package/dist/esm/handleContentDeclarationFileChange.mjs +2 -2
- package/dist/esm/handleUnlinkedContentDeclarationFile.mjs +1 -1
- package/dist/esm/init/frameworkSetup/nextAppRouter/restructure.mjs +1 -1
- package/dist/esm/init/frameworkSetup/tanstackStart/restructure.mjs +1 -1
- package/dist/esm/init/index.mjs +306 -301
- package/dist/esm/init/index.mjs.map +1 -1
- package/dist/esm/init/upgradeIntlayerPackages.mjs +57 -0
- package/dist/esm/init/upgradeIntlayerPackages.mjs.map +1 -0
- package/dist/esm/init/utils/fileSystem.mjs +1 -1
- package/dist/esm/init/utils/githubActions.mjs +1 -1
- package/dist/esm/init/utils/index.mjs +3 -2
- package/dist/esm/init/utils/intlayerDependencies.mjs +110 -0
- package/dist/esm/init/utils/intlayerDependencies.mjs.map +1 -0
- package/dist/esm/init/utils/packageManager.mjs +143 -93
- package/dist/esm/init/utils/packageManager.mjs.map +1 -1
- package/dist/esm/initConfig/index.mjs +1 -1
- package/dist/esm/installLSP.mjs +1 -1
- package/dist/esm/installMCP/installMCP.mjs +1 -1
- package/dist/esm/installSkills/index.mjs +111 -20
- package/dist/esm/installSkills/index.mjs.map +1 -1
- package/dist/esm/listDictionariesPath.mjs +1 -1
- package/dist/esm/listGitFiles.mjs +1 -1
- package/dist/esm/loadDictionaries/getIntlayerBundle.mjs +2 -2
- package/dist/esm/loadDictionaries/index.mjs +1 -1
- package/dist/esm/loadDictionaries/loadContentDeclaration.mjs +2 -2
- package/dist/esm/loadDictionaries/loadDictionaries.mjs +1 -1
- package/dist/esm/loadDictionaries/loadLocalDictionaries.mjs +1 -1
- package/dist/esm/loadDictionaries/loadMarkdownContentDeclaration.mjs +1 -1
- package/dist/esm/logConfigDetails.mjs +1 -1
- package/dist/esm/prepareIntlayer.mjs +4 -4
- package/dist/esm/scan/index.mjs +1 -1
- package/dist/esm/scan/scanWebsite.mjs +1 -1
- package/dist/esm/syncPluginKit/createFileAdapter.mjs +1 -1
- package/dist/esm/syncPluginKit/index.mjs +1 -1
- package/dist/esm/utils/buildComponentFilesList.mjs +1 -1
- package/dist/esm/utils/contentWatcherLock.mjs +2 -2
- package/dist/esm/utils/index.mjs +4 -4
- package/dist/esm/utils/readDictionariesFromDisk.mjs +1 -1
- package/dist/esm/utils/runOnce.mjs +1 -1
- package/dist/esm/utils/runParallel/pidTree.mjs +1 -1
- package/dist/esm/utils/withFileLock.mjs +1 -1
- package/dist/esm/watcher.mjs +6 -6
- package/dist/esm/writeConfiguration/index.mjs +1 -1
- package/dist/esm/writeContentDeclaration/processContentDeclarationContent.mjs +2 -2
- package/dist/esm/writeContentDeclaration/transformJSFile.mjs +1 -1
- package/dist/esm/writeContentDeclaration/writeContentDeclaration.mjs +4 -4
- package/dist/esm/writeContentDeclaration/writeJSFile.mjs +3 -3
- package/dist/esm/writeContentDeclaration/writeMarkdownFile.mjs +1 -1
- package/dist/esm/writeContentDeclaration/writeYamlFile.mjs +1 -1
- package/dist/esm/writeFileIfChanged.mjs +1 -1
- package/dist/types/cli.d.ts +2 -1
- package/dist/types/init/index.d.ts +9 -6
- package/dist/types/init/index.d.ts.map +1 -1
- package/dist/types/init/upgradeIntlayerPackages.d.ts +26 -0
- package/dist/types/init/upgradeIntlayerPackages.d.ts.map +1 -0
- package/dist/types/init/utils/index.d.ts +3 -2
- package/dist/types/init/utils/intlayerDependencies.d.ts +66 -0
- package/dist/types/init/utils/intlayerDependencies.d.ts.map +1 -0
- package/dist/types/init/utils/packageManager.d.ts +44 -19
- package/dist/types/init/utils/packageManager.d.ts.map +1 -1
- package/dist/types/installSkills/index.d.ts +16 -3
- package/dist/types/installSkills/index.d.ts.map +1 -1
- package/package.json +7 -7
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
+
const require_runtime = require('../../_virtual/_rolldown/runtime.cjs');
|
|
3
|
+
const require_init_utils_packageManager = require('./packageManager.cjs');
|
|
4
|
+
let node_fs_promises = require("node:fs/promises");
|
|
5
|
+
let node_path = require("node:path");
|
|
6
|
+
let _intlayer_config_defaultValues = require("@intlayer/config/defaultValues");
|
|
7
|
+
let fast_glob = require("fast-glob");
|
|
8
|
+
fast_glob = require_runtime.__toESM(fast_glob);
|
|
9
|
+
|
|
10
|
+
//#region src/init/utils/intlayerDependencies.ts
|
|
11
|
+
/** Dependency fields of a `package.json` scanned for Intlayer packages. */
|
|
12
|
+
const DEPENDENCY_FIELDS = ["dependencies", "devDependencies"];
|
|
13
|
+
/**
|
|
14
|
+
* Ranges that do not point to the registry (monorepo workspaces, local links,
|
|
15
|
+
* aliases, catalogs, git…). They are managed by the user and never rewritten.
|
|
16
|
+
*/
|
|
17
|
+
const isRegistryRange = (range) => /^[\^~]?\d/.test(range.trim());
|
|
18
|
+
/**
|
|
19
|
+
* Lists every `package.json` of the project (root first), skipping
|
|
20
|
+
* `node_modules` and build outputs.
|
|
21
|
+
*/
|
|
22
|
+
const findPackageJsonFiles = async (rootDir) => {
|
|
23
|
+
return (await (0, fast_glob.default)("**/package.json", {
|
|
24
|
+
cwd: rootDir,
|
|
25
|
+
ignore: [..._intlayer_config_defaultValues.EXCLUDED_PATHS, "**/.git/**"]
|
|
26
|
+
})).sort((first, second) => first === "package.json" ? -1 : second === "package.json" ? 1 : first.localeCompare(second));
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Lists the Intlayer packages (`intlayer`, `@intlayer/*`, `*-intlayer`,
|
|
30
|
+
* `intlayer-*`) declared with a registry range in a parsed `package.json`.
|
|
31
|
+
*/
|
|
32
|
+
const getIntlayerDependencies = (packageJson) => DEPENDENCY_FIELDS.flatMap((dependencyField) => Object.entries(packageJson[dependencyField] ?? {}).filter(([packageName, range]) => require_init_utils_packageManager.isIntlayerPackageName(packageName) && isRegistryRange(range)).map(([packageName, currentRange]) => ({
|
|
33
|
+
packageName,
|
|
34
|
+
dependencyField,
|
|
35
|
+
currentRange
|
|
36
|
+
})));
|
|
37
|
+
/** Lists the Intlayer dependencies of every `package.json` of the project. */
|
|
38
|
+
const listIntlayerDependencies = async (rootDir) => {
|
|
39
|
+
const packageJsonPaths = await findPackageJsonFiles(rootDir);
|
|
40
|
+
return (await Promise.all(packageJsonPaths.map(async (packageJsonPath) => {
|
|
41
|
+
try {
|
|
42
|
+
const packageJson = JSON.parse(await (0, node_fs_promises.readFile)((0, node_path.join)(rootDir, packageJsonPath), "utf8"));
|
|
43
|
+
return {
|
|
44
|
+
packageJsonPath,
|
|
45
|
+
dependencies: getIntlayerDependencies(packageJson)
|
|
46
|
+
};
|
|
47
|
+
} catch {
|
|
48
|
+
return {
|
|
49
|
+
packageJsonPath,
|
|
50
|
+
dependencies: []
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}))).filter(({ dependencies }) => dependencies.length > 0);
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Fetches the version a dist-tag (`latest` by default) of a package points to
|
|
57
|
+
* on the npm registry. Resolves to `null` when the registry cannot be reached,
|
|
58
|
+
* the package is not published or the dist-tag does not exist.
|
|
59
|
+
*/
|
|
60
|
+
const fetchLatestPackageVersion = async (packageName, { distTag = "latest", registryUrl = "https://registry.npmjs.org" } = {}) => {
|
|
61
|
+
try {
|
|
62
|
+
const response = await fetch(`${registryUrl}/${packageName.replace("/", "%2F")}/${encodeURIComponent(distTag)}`, { signal: AbortSignal.timeout(1e4) });
|
|
63
|
+
if (!response.ok) return null;
|
|
64
|
+
const { version } = await response.json();
|
|
65
|
+
return typeof version === "string" ? version : null;
|
|
66
|
+
} catch {
|
|
67
|
+
return null;
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
/**
|
|
71
|
+
* Keeps the range operator (`^`, `~` or none) of `currentRange` and points it
|
|
72
|
+
* to `version`.
|
|
73
|
+
*
|
|
74
|
+
* @example toRange('^9.0.0', '9.5.7') // '^9.5.7'
|
|
75
|
+
*/
|
|
76
|
+
const toRange = (currentRange, version) => `${currentRange.trim().match(/^[\^~]/)?.[0] ?? ""}${version}`;
|
|
77
|
+
/**
|
|
78
|
+
* Computes the upgrades bringing every listed dependency to its latest version.
|
|
79
|
+
* Dependencies already on the latest version, or whose latest version could not
|
|
80
|
+
* be fetched, are left out.
|
|
81
|
+
*/
|
|
82
|
+
const getIntlayerDependencyUpgrades = (packageJsonDependencies, latestVersions) => packageJsonDependencies.flatMap(({ packageJsonPath, dependencies }) => dependencies.flatMap((dependency) => {
|
|
83
|
+
const latestVersion = latestVersions.get(dependency.packageName);
|
|
84
|
+
if (!latestVersion || require_init_utils_packageManager.normalizeVersion(dependency.currentRange) === require_init_utils_packageManager.normalizeVersion(latestVersion)) return [];
|
|
85
|
+
return [{
|
|
86
|
+
...dependency,
|
|
87
|
+
packageJsonPath,
|
|
88
|
+
nextRange: toRange(dependency.currentRange, latestVersion)
|
|
89
|
+
}];
|
|
90
|
+
}));
|
|
91
|
+
/**
|
|
92
|
+
* Writes the upgraded ranges back to their `package.json`, keeping the file's
|
|
93
|
+
* indentation and trailing newline.
|
|
94
|
+
*/
|
|
95
|
+
const writeIntlayerDependencyUpgrades = async (rootDir, upgrades) => {
|
|
96
|
+
const packageJsonPaths = [...new Set(upgrades.map(({ packageJsonPath }) => packageJsonPath))];
|
|
97
|
+
for (const packageJsonPath of packageJsonPaths) {
|
|
98
|
+
const absolutePath = (0, node_path.join)(rootDir, packageJsonPath);
|
|
99
|
+
const content = await (0, node_fs_promises.readFile)(absolutePath, "utf8");
|
|
100
|
+
const packageJson = JSON.parse(content);
|
|
101
|
+
for (const upgrade of upgrades) {
|
|
102
|
+
if (upgrade.packageJsonPath !== packageJsonPath) continue;
|
|
103
|
+
packageJson[upgrade.dependencyField][upgrade.packageName] = upgrade.nextRange;
|
|
104
|
+
}
|
|
105
|
+
const indentation = content.match(/^[ \t]+(?=")/m)?.[0] ?? 2;
|
|
106
|
+
const trailingNewline = content.endsWith("\n") ? "\n" : "";
|
|
107
|
+
await (0, node_fs_promises.writeFile)(absolutePath, `${JSON.stringify(packageJson, null, indentation)}${trailingNewline}`, "utf8");
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
//#endregion
|
|
112
|
+
exports.fetchLatestPackageVersion = fetchLatestPackageVersion;
|
|
113
|
+
exports.findPackageJsonFiles = findPackageJsonFiles;
|
|
114
|
+
exports.getIntlayerDependencies = getIntlayerDependencies;
|
|
115
|
+
exports.getIntlayerDependencyUpgrades = getIntlayerDependencyUpgrades;
|
|
116
|
+
exports.listIntlayerDependencies = listIntlayerDependencies;
|
|
117
|
+
exports.toRange = toRange;
|
|
118
|
+
exports.writeIntlayerDependencyUpgrades = writeIntlayerDependencyUpgrades;
|
|
119
|
+
//# sourceMappingURL=intlayerDependencies.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intlayerDependencies.cjs","names":["fg","EXCLUDED_PATHS","isIntlayerPackageName","readFile","join","normalizeVersion","writeFile"],"sources":["../../../../src/init/utils/intlayerDependencies.ts"],"sourcesContent":["import { readFile, writeFile } from 'node:fs/promises';\nimport { join } from 'node:path';\nimport { EXCLUDED_PATHS } from '@intlayer/config/defaultValues';\nimport fg from 'fast-glob';\nimport { isIntlayerPackageName, normalizeVersion } from './packageManager';\n\n/** Dependency fields of a `package.json` scanned for Intlayer packages. */\nconst DEPENDENCY_FIELDS = ['dependencies', 'devDependencies'] as const;\n\ntype DependencyField = (typeof DEPENDENCY_FIELDS)[number];\n\n/** An Intlayer dependency declared in one of the project's `package.json`. */\nexport type IntlayerDependency = {\n /** Package name, e.g. `next-intlayer`. */\n packageName: string;\n /** Field the dependency is declared in. */\n dependencyField: DependencyField;\n /** Declared version range, e.g. `^9.5.0`. */\n currentRange: string;\n};\n\n/** Intlayer dependencies of one `package.json`. */\nexport type PackageJsonIntlayerDependencies = {\n /** Path of the `package.json`, relative to the project root. */\n packageJsonPath: string;\n dependencies: IntlayerDependency[];\n};\n\n/** A dependency range rewritten to the latest published version. */\nexport type IntlayerDependencyUpgrade = IntlayerDependency & {\n packageJsonPath: string;\n /** Range written back to the `package.json`, e.g. `^9.5.7`. */\n nextRange: string;\n};\n\n/**\n * Ranges that do not point to the registry (monorepo workspaces, local links,\n * aliases, catalogs, git…). They are managed by the user and never rewritten.\n */\nconst isRegistryRange = (range: string): boolean =>\n /^[\\^~]?\\d/.test(range.trim());\n\n/**\n * Lists every `package.json` of the project (root first), skipping\n * `node_modules` and build outputs.\n */\nexport const findPackageJsonFiles = async (\n rootDir: string\n): Promise<string[]> => {\n const packageJsonFiles = await fg('**/package.json', {\n cwd: rootDir,\n ignore: [...EXCLUDED_PATHS, '**/.git/**'],\n });\n\n return packageJsonFiles.sort((first, second) =>\n first === 'package.json'\n ? -1\n : second === 'package.json'\n ? 1\n : first.localeCompare(second)\n );\n};\n\n/**\n * Lists the Intlayer packages (`intlayer`, `@intlayer/*`, `*-intlayer`,\n * `intlayer-*`) declared with a registry range in a parsed `package.json`.\n */\nexport const getIntlayerDependencies = (\n packageJson: Partial<Record<DependencyField, Record<string, string>>>\n): IntlayerDependency[] =>\n DEPENDENCY_FIELDS.flatMap((dependencyField) =>\n Object.entries(packageJson[dependencyField] ?? {})\n .filter(\n ([packageName, range]) =>\n isIntlayerPackageName(packageName) && isRegistryRange(range)\n )\n .map(([packageName, currentRange]) => ({\n packageName,\n dependencyField,\n currentRange,\n }))\n );\n\n/** Lists the Intlayer dependencies of every `package.json` of the project. */\nexport const listIntlayerDependencies = async (\n rootDir: string\n): Promise<PackageJsonIntlayerDependencies[]> => {\n const packageJsonPaths = await findPackageJsonFiles(rootDir);\n\n const results = await Promise.all(\n packageJsonPaths.map(async (packageJsonPath) => {\n try {\n const packageJson = JSON.parse(\n await readFile(join(rootDir, packageJsonPath), 'utf8')\n );\n return {\n packageJsonPath,\n dependencies: getIntlayerDependencies(packageJson),\n };\n } catch {\n return { packageJsonPath, dependencies: [] };\n }\n })\n );\n\n return results.filter(({ dependencies }) => dependencies.length > 0);\n};\n\n/**\n * Fetches the version a dist-tag (`latest` by default) of a package points to\n * on the npm registry. Resolves to `null` when the registry cannot be reached,\n * the package is not published or the dist-tag does not exist.\n */\nexport const fetchLatestPackageVersion = async (\n packageName: string,\n {\n distTag = 'latest',\n registryUrl = 'https://registry.npmjs.org',\n }: { distTag?: string; registryUrl?: string } = {}\n): Promise<string | null> => {\n try {\n const response = await fetch(\n `${registryUrl}/${packageName.replace('/', '%2F')}/${encodeURIComponent(distTag)}`,\n { signal: AbortSignal.timeout(10_000) }\n );\n if (!response.ok) return null;\n\n const { version } = (await response.json()) as { version?: unknown };\n return typeof version === 'string' ? version : null;\n } catch {\n return null;\n }\n};\n\n/**\n * Keeps the range operator (`^`, `~` or none) of `currentRange` and points it\n * to `version`.\n *\n * @example toRange('^9.0.0', '9.5.7') // '^9.5.7'\n */\nexport const toRange = (currentRange: string, version: string): string =>\n `${currentRange.trim().match(/^[\\^~]/)?.[0] ?? ''}${version}`;\n\n/**\n * Computes the upgrades bringing every listed dependency to its latest version.\n * Dependencies already on the latest version, or whose latest version could not\n * be fetched, are left out.\n */\nexport const getIntlayerDependencyUpgrades = (\n packageJsonDependencies: PackageJsonIntlayerDependencies[],\n latestVersions: Map<string, string | null>\n): IntlayerDependencyUpgrade[] =>\n packageJsonDependencies.flatMap(({ packageJsonPath, dependencies }) =>\n dependencies.flatMap((dependency) => {\n const latestVersion = latestVersions.get(dependency.packageName);\n\n if (\n !latestVersion ||\n normalizeVersion(dependency.currentRange) ===\n normalizeVersion(latestVersion)\n ) {\n return [];\n }\n\n return [\n {\n ...dependency,\n packageJsonPath,\n nextRange: toRange(dependency.currentRange, latestVersion),\n },\n ];\n })\n );\n\n/**\n * Writes the upgraded ranges back to their `package.json`, keeping the file's\n * indentation and trailing newline.\n */\nexport const writeIntlayerDependencyUpgrades = async (\n rootDir: string,\n upgrades: IntlayerDependencyUpgrade[]\n): Promise<void> => {\n const packageJsonPaths = [\n ...new Set(upgrades.map(({ packageJsonPath }) => packageJsonPath)),\n ];\n\n for (const packageJsonPath of packageJsonPaths) {\n const absolutePath = join(rootDir, packageJsonPath);\n const content = await readFile(absolutePath, 'utf8');\n const packageJson = JSON.parse(content);\n\n for (const upgrade of upgrades) {\n if (upgrade.packageJsonPath !== packageJsonPath) continue;\n packageJson[upgrade.dependencyField][upgrade.packageName] =\n upgrade.nextRange;\n }\n\n const indentation = content.match(/^[ \\t]+(?=\")/m)?.[0] ?? 2;\n const trailingNewline = content.endsWith('\\n') ? '\\n' : '';\n\n await writeFile(\n absolutePath,\n `${JSON.stringify(packageJson, null, indentation)}${trailingNewline}`,\n 'utf8'\n );\n }\n};\n"],"mappings":"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"}
|
|
@@ -1,19 +1,58 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
2
|
-
let node_path = require("node:path");
|
|
3
|
-
let _intlayer_config_utils = require("@intlayer/config/utils");
|
|
4
2
|
let node_fs = require("node:fs");
|
|
3
|
+
let node_path = require("node:path");
|
|
5
4
|
let node_child_process = require("node:child_process");
|
|
6
5
|
|
|
7
6
|
//#region src/init/utils/packageManager.ts
|
|
7
|
+
/** Lock files revealing the package manager, in detection priority order. */
|
|
8
|
+
const LOCK_FILE_PACKAGE_MANAGERS = [
|
|
9
|
+
["bun.lock", "bun"],
|
|
10
|
+
["bun.lockb", "bun"],
|
|
11
|
+
["pnpm-lock.yaml", "pnpm"],
|
|
12
|
+
["yarn.lock", "yarn"],
|
|
13
|
+
["package-lock.json", "npm"]
|
|
14
|
+
];
|
|
15
|
+
/** Package managers accepted in the `packageManager` field of `package.json`. */
|
|
16
|
+
const PACKAGE_MANAGERS = [
|
|
17
|
+
"bun",
|
|
18
|
+
"pnpm",
|
|
19
|
+
"yarn",
|
|
20
|
+
"npm"
|
|
21
|
+
];
|
|
22
|
+
/**
|
|
23
|
+
* Reads the package manager pinned by the `packageManager` field of the
|
|
24
|
+
* `package.json` in `directory` (e.g. `"pnpm@9.0.0"`), if any.
|
|
25
|
+
*/
|
|
26
|
+
const readPackageManagerField = (directory) => {
|
|
27
|
+
try {
|
|
28
|
+
const { packageManager } = JSON.parse((0, node_fs.readFileSync)((0, node_path.join)(directory, "package.json"), "utf8"));
|
|
29
|
+
if (typeof packageManager !== "string") return null;
|
|
30
|
+
const name = packageManager.split("@")[0];
|
|
31
|
+
return PACKAGE_MANAGERS.includes(name) ? name : null;
|
|
32
|
+
} catch {
|
|
33
|
+
return null;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
8
36
|
/**
|
|
9
37
|
* Detects the package manager in use by checking for lock files in the
|
|
10
|
-
* project root
|
|
38
|
+
* project root, then the `packageManager` field of its `package.json`. Falls
|
|
39
|
+
* back to npm when neither is found.
|
|
40
|
+
*/
|
|
41
|
+
const detectPackageManager = (rootDir) => LOCK_FILE_PACKAGE_MANAGERS.find(([lockFile]) => (0, node_fs.existsSync)((0, node_path.join)(rootDir, lockFile)))?.[1] ?? readPackageManagerField(rootDir) ?? "npm";
|
|
42
|
+
/**
|
|
43
|
+
* Walks up from `startDir` to the nearest directory holding a lock file — the
|
|
44
|
+
* workspace root an install must run from. Stops at the repository root
|
|
45
|
+
* (`.git`) and returns `null` when no lock file is found.
|
|
11
46
|
*/
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
47
|
+
const findLockFileDir = (startDir) => {
|
|
48
|
+
let currentDir = (0, node_path.resolve)(startDir);
|
|
49
|
+
while (true) {
|
|
50
|
+
if (LOCK_FILE_PACKAGE_MANAGERS.some(([lockFile]) => (0, node_fs.existsSync)((0, node_path.join)(currentDir, lockFile)))) return currentDir;
|
|
51
|
+
if ((0, node_fs.existsSync)((0, node_path.join)(currentDir, ".git"))) return null;
|
|
52
|
+
const parentDir = (0, node_path.dirname)(currentDir);
|
|
53
|
+
if (parentDir === currentDir) return null;
|
|
54
|
+
currentDir = parentDir;
|
|
55
|
+
}
|
|
17
56
|
};
|
|
18
57
|
/**
|
|
19
58
|
* Returns the install command for the given package manager and package list.
|
|
@@ -41,7 +80,11 @@ const COMPAT_I18N_LIBRARIES = [
|
|
|
41
80
|
"react-i18next",
|
|
42
81
|
"@intlayer/i18next",
|
|
43
82
|
"@intlayer/react-i18next"
|
|
44
|
-
]
|
|
83
|
+
],
|
|
84
|
+
replacements: {
|
|
85
|
+
i18next: "@intlayer/i18next",
|
|
86
|
+
"react-i18next": "@intlayer/react-i18next"
|
|
87
|
+
}
|
|
45
88
|
},
|
|
46
89
|
{
|
|
47
90
|
label: "next-intl / use-intl",
|
|
@@ -50,27 +93,36 @@ const COMPAT_I18N_LIBRARIES = [
|
|
|
50
93
|
"use-intl",
|
|
51
94
|
"@intlayer/next-intl",
|
|
52
95
|
"@intlayer/use-intl"
|
|
53
|
-
]
|
|
96
|
+
],
|
|
97
|
+
replacements: {
|
|
98
|
+
"next-intl": "@intlayer/next-intl",
|
|
99
|
+
"use-intl": "@intlayer/use-intl"
|
|
100
|
+
}
|
|
54
101
|
},
|
|
55
102
|
{
|
|
56
103
|
label: "vue-i18n",
|
|
57
|
-
packages: ["vue-i18n", "@intlayer/vue-i18n"]
|
|
104
|
+
packages: ["vue-i18n", "@intlayer/vue-i18n"],
|
|
105
|
+
replacements: { "vue-i18n": "@intlayer/vue-i18n" }
|
|
58
106
|
},
|
|
59
107
|
{
|
|
60
108
|
label: "@nuxtjs/i18n",
|
|
61
|
-
packages: ["@nuxtjs/i18n", "@intlayer/nuxtjs-i18n"]
|
|
109
|
+
packages: ["@nuxtjs/i18n", "@intlayer/nuxtjs-i18n"],
|
|
110
|
+
replacements: { "@nuxtjs/i18n": "@intlayer/nuxtjs-i18n" }
|
|
62
111
|
},
|
|
63
112
|
{
|
|
64
113
|
label: "next-i18next",
|
|
65
|
-
packages: ["next-i18next", "@intlayer/next-i18next"]
|
|
114
|
+
packages: ["next-i18next", "@intlayer/next-i18next"],
|
|
115
|
+
replacements: { "next-i18next": "@intlayer/next-i18next" }
|
|
66
116
|
},
|
|
67
117
|
{
|
|
68
118
|
label: "next-translate",
|
|
69
|
-
packages: ["next-translate", "@intlayer/next-translate"]
|
|
119
|
+
packages: ["next-translate", "@intlayer/next-translate"],
|
|
120
|
+
replacements: { "next-translate": "@intlayer/next-translate" }
|
|
70
121
|
},
|
|
71
122
|
{
|
|
72
123
|
label: "react-intl",
|
|
73
|
-
packages: ["react-intl", "@intlayer/react-intl"]
|
|
124
|
+
packages: ["react-intl", "@intlayer/react-intl"],
|
|
125
|
+
replacements: { "react-intl": "@intlayer/react-intl" }
|
|
74
126
|
},
|
|
75
127
|
{
|
|
76
128
|
label: "Lingui",
|
|
@@ -78,30 +130,63 @@ const COMPAT_I18N_LIBRARIES = [
|
|
|
78
130
|
"@lingui/core",
|
|
79
131
|
"@lingui/react",
|
|
80
132
|
"@intlayer/lingui"
|
|
81
|
-
]
|
|
133
|
+
],
|
|
134
|
+
replacements: {
|
|
135
|
+
"@lingui/core": "@intlayer/lingui",
|
|
136
|
+
"@lingui/react": "@intlayer/lingui"
|
|
137
|
+
}
|
|
82
138
|
},
|
|
83
139
|
{
|
|
84
140
|
label: "svelte-i18n",
|
|
85
|
-
packages: ["svelte-i18n", "@intlayer/svelte-i18n"]
|
|
141
|
+
packages: ["svelte-i18n", "@intlayer/svelte-i18n"],
|
|
142
|
+
replacements: { "svelte-i18n": "@intlayer/svelte-i18n" }
|
|
86
143
|
},
|
|
87
144
|
{
|
|
88
145
|
label: "@ngneat/transloco",
|
|
89
|
-
packages: ["@ngneat/transloco", "@intlayer/transloco"]
|
|
146
|
+
packages: ["@ngneat/transloco", "@intlayer/transloco"],
|
|
147
|
+
replacements: { "@ngneat/transloco": "@intlayer/transloco" }
|
|
90
148
|
},
|
|
91
149
|
{
|
|
92
150
|
label: "@ngx-translate/core",
|
|
93
|
-
packages: ["@ngx-translate/core", "@intlayer/ngx-translate"]
|
|
151
|
+
packages: ["@ngx-translate/core", "@intlayer/ngx-translate"],
|
|
152
|
+
replacements: { "@ngx-translate/core": "@intlayer/ngx-translate" }
|
|
94
153
|
},
|
|
95
154
|
{
|
|
96
155
|
label: "node-polyglot",
|
|
97
|
-
packages: ["node-polyglot", "@intlayer/polyglot"]
|
|
156
|
+
packages: ["node-polyglot", "@intlayer/polyglot"],
|
|
157
|
+
replacements: { "node-polyglot": "@intlayer/polyglot" }
|
|
98
158
|
},
|
|
99
159
|
{
|
|
100
160
|
label: "i18n-js",
|
|
101
|
-
packages: ["i18n-js", "@intlayer/i18n-js"]
|
|
161
|
+
packages: ["i18n-js", "@intlayer/i18n-js"],
|
|
162
|
+
replacements: { "i18n-js": "@intlayer/i18n-js" }
|
|
102
163
|
}
|
|
103
164
|
];
|
|
104
165
|
/**
|
|
166
|
+
* Maps third-party i18n libraries to the Intlayer compat adapter that replaces
|
|
167
|
+
* them at runtime, derived from {@link COMPAT_I18N_LIBRARIES}.
|
|
168
|
+
*/
|
|
169
|
+
const COMPAT_PACKAGE_REPLACEMENTS = Object.fromEntries(COMPAT_I18N_LIBRARIES.flatMap((library) => Object.entries(library.replacements)));
|
|
170
|
+
/**
|
|
171
|
+
* When a project uses a compat i18n package (such as `next-intl`) that gets
|
|
172
|
+
* replaced by an `@intlayer/*` adapter (e.g. `@intlayer/next-intl`), moves the
|
|
173
|
+
* original package from `dependencies` to `devDependencies` in `package.json`.
|
|
174
|
+
*
|
|
175
|
+
* Returns the list of package names that were moved.
|
|
176
|
+
*/
|
|
177
|
+
const moveCompatPackagesToDevDependencies = (packageJson) => {
|
|
178
|
+
const movedPackages = [];
|
|
179
|
+
if (!packageJson.dependencies) return movedPackages;
|
|
180
|
+
for (const compatPackage of Object.keys(COMPAT_PACKAGE_REPLACEMENTS)) if (packageJson.dependencies[compatPackage]) {
|
|
181
|
+
const version = packageJson.dependencies[compatPackage];
|
|
182
|
+
delete packageJson.dependencies[compatPackage];
|
|
183
|
+
packageJson.devDependencies = packageJson.devDependencies ?? {};
|
|
184
|
+
if (!packageJson.devDependencies[compatPackage]) packageJson.devDependencies[compatPackage] = version;
|
|
185
|
+
movedPackages.push(compatPackage);
|
|
186
|
+
}
|
|
187
|
+
return movedPackages;
|
|
188
|
+
};
|
|
189
|
+
/**
|
|
105
190
|
* Returns the labels of the compat i18n libraries present in `dependencies`.
|
|
106
191
|
*
|
|
107
192
|
* Lets the init flow report (and branch on) the libraries it found without
|
|
@@ -126,6 +211,7 @@ const hasLintTooling = (dependencies) => Boolean(dependencies.eslint) || Boolean
|
|
|
126
211
|
const detectMissingIntlayerPackages = (allDependencies, options = {}) => {
|
|
127
212
|
const packagesToInstall = [];
|
|
128
213
|
const devPackagesToInstall = [];
|
|
214
|
+
const packagesToMoveToDev = [];
|
|
129
215
|
let compatSyncConfig;
|
|
130
216
|
let compatVitePluginConfig;
|
|
131
217
|
const isInstalled = (packageName) => Boolean(allDependencies[packageName]);
|
|
@@ -135,6 +221,16 @@ const detectMissingIntlayerPackages = (allDependencies, options = {}) => {
|
|
|
135
221
|
const addDevIfMissing = (packageName) => {
|
|
136
222
|
if (!isInstalled(packageName)) devPackagesToInstall.push(packageName);
|
|
137
223
|
};
|
|
224
|
+
const markCompatReplacement = (originalPackage, adapterPackage) => {
|
|
225
|
+
addIfMissing(adapterPackage);
|
|
226
|
+
addDevIfMissing(originalPackage);
|
|
227
|
+
const isExplicitDev = Boolean(options.devDependencies?.[originalPackage]);
|
|
228
|
+
const isExplicitProd = Boolean(options.dependencies?.[originalPackage]);
|
|
229
|
+
const isImplicitProd = !options.dependencies && !options.devDependencies && Boolean(allDependencies[originalPackage]);
|
|
230
|
+
if ((isExplicitProd || isImplicitProd) && !isExplicitDev) {
|
|
231
|
+
if (!packagesToMoveToDev.includes(originalPackage)) packagesToMoveToDev.push(originalPackage);
|
|
232
|
+
}
|
|
233
|
+
};
|
|
138
234
|
addIfMissing("intlayer");
|
|
139
235
|
const isReactNativeProject = isInstalled("react-native") || isInstalled("expo");
|
|
140
236
|
if (isInstalled("next")) addIfMissing("next-intlayer");
|
|
@@ -147,8 +243,7 @@ const detectMissingIntlayerPackages = (allDependencies, options = {}) => {
|
|
|
147
243
|
if (isInstalled("vite")) addIfMissing("vite-intlayer");
|
|
148
244
|
if (hasLintTooling(allDependencies)) addDevIfMissing("eslint-plugin-intlayer");
|
|
149
245
|
if (isInstalled("next-intl") || isInstalled("@intlayer/next-intl")) {
|
|
150
|
-
|
|
151
|
-
addIfMissing("next-intl");
|
|
246
|
+
markCompatReplacement("next-intl", "@intlayer/next-intl");
|
|
152
247
|
compatSyncConfig ??= {
|
|
153
248
|
format: "icu",
|
|
154
249
|
sourceTemplate: "./messages/${locale}.json",
|
|
@@ -156,24 +251,21 @@ const detectMissingIntlayerPackages = (allDependencies, options = {}) => {
|
|
|
156
251
|
};
|
|
157
252
|
}
|
|
158
253
|
if (isInstalled("next-i18next") || isInstalled("@intlayer/next-i18next")) {
|
|
159
|
-
|
|
160
|
-
addIfMissing("next-i18next");
|
|
254
|
+
markCompatReplacement("next-i18next", "@intlayer/next-i18next");
|
|
161
255
|
compatSyncConfig ??= {
|
|
162
256
|
format: "i18next",
|
|
163
257
|
sourceTemplate: "./src/locales/${locale}/${key}.json"
|
|
164
258
|
};
|
|
165
259
|
}
|
|
166
260
|
if (isInstalled("next-translate") || isInstalled("@intlayer/next-translate")) {
|
|
167
|
-
|
|
168
|
-
addIfMissing("next-translate");
|
|
261
|
+
markCompatReplacement("next-translate", "@intlayer/next-translate");
|
|
169
262
|
compatSyncConfig ??= {
|
|
170
263
|
format: "i18next",
|
|
171
264
|
sourceTemplate: "./locales/${locale}/${key}.json"
|
|
172
265
|
};
|
|
173
266
|
}
|
|
174
267
|
if (isInstalled("i18next") || isInstalled("@intlayer/i18next")) {
|
|
175
|
-
|
|
176
|
-
addIfMissing("i18next");
|
|
268
|
+
markCompatReplacement("i18next", "@intlayer/i18next");
|
|
177
269
|
compatSyncConfig ??= {
|
|
178
270
|
format: "i18next",
|
|
179
271
|
sourceTemplate: "./src/locales/${locale}/${key}.json"
|
|
@@ -184,8 +276,7 @@ const detectMissingIntlayerPackages = (allDependencies, options = {}) => {
|
|
|
184
276
|
};
|
|
185
277
|
}
|
|
186
278
|
if (isInstalled("react-i18next") || isInstalled("@intlayer/react-i18next")) {
|
|
187
|
-
|
|
188
|
-
addIfMissing("react-i18next");
|
|
279
|
+
markCompatReplacement("react-i18next", "@intlayer/react-i18next");
|
|
189
280
|
compatSyncConfig ??= {
|
|
190
281
|
format: "i18next",
|
|
191
282
|
sourceTemplate: "./src/locales/${locale}/${key}.json"
|
|
@@ -196,8 +287,7 @@ const detectMissingIntlayerPackages = (allDependencies, options = {}) => {
|
|
|
196
287
|
};
|
|
197
288
|
}
|
|
198
289
|
if (isInstalled("vue-i18n") || isInstalled("@intlayer/vue-i18n")) {
|
|
199
|
-
|
|
200
|
-
addIfMissing("vue-i18n");
|
|
290
|
+
markCompatReplacement("vue-i18n", "@intlayer/vue-i18n");
|
|
201
291
|
compatSyncConfig ??= {
|
|
202
292
|
format: "vue-i18n",
|
|
203
293
|
sourceTemplate: "./locales/${locale}/${key}.json"
|
|
@@ -208,8 +298,7 @@ const detectMissingIntlayerPackages = (allDependencies, options = {}) => {
|
|
|
208
298
|
};
|
|
209
299
|
}
|
|
210
300
|
if (isInstalled("use-intl") || isInstalled("@intlayer/use-intl")) {
|
|
211
|
-
|
|
212
|
-
addIfMissing("use-intl");
|
|
301
|
+
markCompatReplacement("use-intl", "@intlayer/use-intl");
|
|
213
302
|
compatSyncConfig ??= {
|
|
214
303
|
format: "icu",
|
|
215
304
|
sourceTemplate: "./messages/${locale}.json",
|
|
@@ -221,8 +310,7 @@ const detectMissingIntlayerPackages = (allDependencies, options = {}) => {
|
|
|
221
310
|
};
|
|
222
311
|
}
|
|
223
312
|
if (isInstalled("react-intl") || isInstalled("@intlayer/react-intl")) {
|
|
224
|
-
|
|
225
|
-
addIfMissing("react-intl");
|
|
313
|
+
markCompatReplacement("react-intl", "@intlayer/react-intl");
|
|
226
314
|
compatSyncConfig ??= {
|
|
227
315
|
format: "icu",
|
|
228
316
|
sourceTemplate: "./src/i18n/${locale}.json"
|
|
@@ -233,16 +321,14 @@ const detectMissingIntlayerPackages = (allDependencies, options = {}) => {
|
|
|
233
321
|
};
|
|
234
322
|
}
|
|
235
323
|
if (isInstalled("@ngneat/transloco") || isInstalled("@intlayer/transloco")) {
|
|
236
|
-
|
|
237
|
-
addIfMissing("@ngneat/transloco");
|
|
324
|
+
markCompatReplacement("@ngneat/transloco", "@intlayer/transloco");
|
|
238
325
|
compatVitePluginConfig ??= {
|
|
239
326
|
pluginFunctionName: "translocoVitePlugin",
|
|
240
327
|
pluginPackageSource: "@intlayer/transloco/plugin"
|
|
241
328
|
};
|
|
242
329
|
}
|
|
243
330
|
if (isInstalled("svelte-i18n") || isInstalled("@intlayer/svelte-i18n")) {
|
|
244
|
-
|
|
245
|
-
addIfMissing("svelte-i18n");
|
|
331
|
+
markCompatReplacement("svelte-i18n", "@intlayer/svelte-i18n");
|
|
246
332
|
compatSyncConfig ??= {
|
|
247
333
|
format: "i18next",
|
|
248
334
|
sourceTemplate: "./src/locales/${locale}.json"
|
|
@@ -253,24 +339,21 @@ const detectMissingIntlayerPackages = (allDependencies, options = {}) => {
|
|
|
253
339
|
};
|
|
254
340
|
}
|
|
255
341
|
if (isInstalled("node-polyglot") || isInstalled("@intlayer/polyglot")) {
|
|
256
|
-
|
|
257
|
-
addIfMissing("node-polyglot");
|
|
342
|
+
markCompatReplacement("node-polyglot", "@intlayer/polyglot");
|
|
258
343
|
compatVitePluginConfig ??= {
|
|
259
344
|
pluginFunctionName: "polyglotVitePlugin",
|
|
260
345
|
pluginPackageSource: "@intlayer/polyglot/plugin"
|
|
261
346
|
};
|
|
262
347
|
}
|
|
263
348
|
if (isInstalled("@nuxtjs/i18n") || isInstalled("@intlayer/nuxtjs-i18n")) {
|
|
264
|
-
|
|
265
|
-
addIfMissing("@nuxtjs/i18n");
|
|
349
|
+
markCompatReplacement("@nuxtjs/i18n", "@intlayer/nuxtjs-i18n");
|
|
266
350
|
compatSyncConfig ??= {
|
|
267
351
|
format: "vue-i18n",
|
|
268
352
|
sourceTemplate: "./locales/${locale}/${key}.json"
|
|
269
353
|
};
|
|
270
354
|
}
|
|
271
355
|
if (isInstalled("@ngx-translate/core") || isInstalled("@intlayer/ngx-translate")) {
|
|
272
|
-
|
|
273
|
-
addIfMissing("@ngx-translate/core");
|
|
356
|
+
markCompatReplacement("@ngx-translate/core", "@intlayer/ngx-translate");
|
|
274
357
|
compatSyncConfig ??= {
|
|
275
358
|
format: "i18next",
|
|
276
359
|
sourceTemplate: "./assets/i18n/${locale}.json"
|
|
@@ -281,8 +364,8 @@ const detectMissingIntlayerPackages = (allDependencies, options = {}) => {
|
|
|
281
364
|
};
|
|
282
365
|
}
|
|
283
366
|
if (isInstalled("@lingui/core") || isInstalled("@lingui/react") || isInstalled("@intlayer/lingui")) {
|
|
284
|
-
|
|
285
|
-
|
|
367
|
+
markCompatReplacement("@lingui/core", "@intlayer/lingui");
|
|
368
|
+
if (isInstalled("@lingui/react")) markCompatReplacement("@lingui/react", "@intlayer/lingui");
|
|
286
369
|
const linguiUsesPo = options.linguiCatalogFormat === "po";
|
|
287
370
|
compatSyncConfig ??= linguiUsesPo ? {
|
|
288
371
|
plugin: "po",
|
|
@@ -303,8 +386,7 @@ const detectMissingIntlayerPackages = (allDependencies, options = {}) => {
|
|
|
303
386
|
};
|
|
304
387
|
}
|
|
305
388
|
if (isInstalled("i18n-js") || isInstalled("@intlayer/i18n-js")) {
|
|
306
|
-
|
|
307
|
-
addIfMissing("i18n-js");
|
|
389
|
+
markCompatReplacement("i18n-js", "@intlayer/i18n-js");
|
|
308
390
|
compatVitePluginConfig ??= {
|
|
309
391
|
pluginFunctionName: "i18nJsVitePlugin",
|
|
310
392
|
pluginPackageSource: "@intlayer/i18n-js/plugin"
|
|
@@ -314,6 +396,7 @@ const detectMissingIntlayerPackages = (allDependencies, options = {}) => {
|
|
|
314
396
|
return {
|
|
315
397
|
packagesToInstall,
|
|
316
398
|
devPackagesToInstall,
|
|
399
|
+
packagesToMoveToDev,
|
|
317
400
|
compatSyncConfig,
|
|
318
401
|
compatVitePluginConfig
|
|
319
402
|
};
|
|
@@ -335,9 +418,10 @@ const installPackages = (rootDir, packages, packageManager, isDev = false) => {
|
|
|
335
418
|
* Matches the core `intlayer` package, every scoped `@intlayer/*` package
|
|
336
419
|
* (including compat adapters such as `@intlayer/next-intl`) and the framework
|
|
337
420
|
* runtime integrations that follow the `<framework>-intlayer` convention
|
|
338
|
-
* (e.g. `next-intlayer`, `react-intlayer`, `express-intlayer`)
|
|
421
|
+
* (e.g. `next-intlayer`, `react-intlayer`, `express-intlayer`), as well as the
|
|
422
|
+
* `intlayer-*` packages (e.g. `intlayer-editor`).
|
|
339
423
|
*/
|
|
340
|
-
const isIntlayerPackageName = (packageName) => packageName === "intlayer" || packageName.startsWith("@intlayer/") ||
|
|
424
|
+
const isIntlayerPackageName = (packageName) => packageName === "intlayer" || packageName.startsWith("@intlayer/") || packageName.startsWith("intlayer-") || packageName.endsWith("-intlayer");
|
|
341
425
|
/**
|
|
342
426
|
* Reduces a semver range or full version to its `major.minor.patch` core,
|
|
343
427
|
* stripping range prefixes (`^`, `~`), pre-release identifiers and build
|
|
@@ -351,46 +435,12 @@ const normalizeVersion = (version) => {
|
|
|
351
435
|
return match ? `${match[1]}.${match[2]}.${match[3]}` : null;
|
|
352
436
|
};
|
|
353
437
|
/**
|
|
354
|
-
*
|
|
355
|
-
*
|
|
356
|
-
*
|
|
438
|
+
* Runs the package manager install command synchronously, so edited
|
|
439
|
+
* `package.json` ranges are resolved and the lock file updated. Throws if the
|
|
440
|
+
* install process exits with a non-zero code.
|
|
357
441
|
*/
|
|
358
|
-
const
|
|
359
|
-
|
|
360
|
-
const manifestPath = (0, node_path.join)(rootDir, "node_modules", packageName, "package.json");
|
|
361
|
-
if (!(0, node_fs.existsSync)(manifestPath)) return null;
|
|
362
|
-
const { version } = JSON.parse((0, node_fs.readFileSync)(manifestPath, "utf-8"));
|
|
363
|
-
return typeof version === "string" ? version : null;
|
|
364
|
-
} catch {
|
|
365
|
-
return null;
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
/**
|
|
369
|
-
* Returns the Intlayer packages from `dependencies` whose installed version is
|
|
370
|
-
* behind `targetVersion` (compared on `major.minor.patch`). Packages that are
|
|
371
|
-
* not installed yet are ignored — those are handled by
|
|
372
|
-
* {@link detectMissingIntlayerPackages}.
|
|
373
|
-
*/
|
|
374
|
-
const detectOutdatedIntlayerPackages = (rootDir, dependencies, targetVersion) => {
|
|
375
|
-
const normalizedTarget = normalizeVersion(targetVersion);
|
|
376
|
-
if (!normalizedTarget) return [];
|
|
377
|
-
return Object.keys(dependencies).filter(isIntlayerPackageName).filter((packageName) => {
|
|
378
|
-
const installedVersion = getInstalledPackageVersion(rootDir, packageName);
|
|
379
|
-
const normalizedInstalled = normalizeVersion(installedVersion ?? void 0);
|
|
380
|
-
if (!normalizedInstalled) return false;
|
|
381
|
-
return (0, _intlayer_config_utils.compareVersions)(normalizedInstalled, "<", normalizedTarget);
|
|
382
|
-
});
|
|
383
|
-
};
|
|
384
|
-
/**
|
|
385
|
-
* Upgrades the given packages to `targetVersion` synchronously, preserving the
|
|
386
|
-
* dependency type via the `isDev` flag. Throws if the install process exits
|
|
387
|
-
* with a non-zero code.
|
|
388
|
-
*/
|
|
389
|
-
const upgradePackages = (rootDir, packages, packageManager, targetVersion, isDev = false) => {
|
|
390
|
-
if (packages.length === 0) return;
|
|
391
|
-
const versionedPackages = packages.map((packageName) => `${packageName}@${targetVersion}`);
|
|
392
|
-
const command = buildInstallCommand(packageManager, versionedPackages, isDev);
|
|
393
|
-
(0, node_child_process.execSync)(command, {
|
|
442
|
+
const runPackageInstall = (rootDir, packageManager) => {
|
|
443
|
+
(0, node_child_process.execSync)(`${packageManager} install`, {
|
|
394
444
|
cwd: rootDir,
|
|
395
445
|
stdio: "inherit"
|
|
396
446
|
});
|
|
@@ -398,14 +448,15 @@ const upgradePackages = (rootDir, packages, packageManager, targetVersion, isDev
|
|
|
398
448
|
|
|
399
449
|
//#endregion
|
|
400
450
|
exports.COMPAT_I18N_LIBRARIES = COMPAT_I18N_LIBRARIES;
|
|
451
|
+
exports.COMPAT_PACKAGE_REPLACEMENTS = COMPAT_PACKAGE_REPLACEMENTS;
|
|
401
452
|
exports.detectCompatI18nLibraries = detectCompatI18nLibraries;
|
|
402
453
|
exports.detectMissingIntlayerPackages = detectMissingIntlayerPackages;
|
|
403
|
-
exports.detectOutdatedIntlayerPackages = detectOutdatedIntlayerPackages;
|
|
404
454
|
exports.detectPackageManager = detectPackageManager;
|
|
405
|
-
exports.
|
|
455
|
+
exports.findLockFileDir = findLockFileDir;
|
|
406
456
|
exports.hasLintTooling = hasLintTooling;
|
|
407
457
|
exports.installPackages = installPackages;
|
|
408
458
|
exports.isIntlayerPackageName = isIntlayerPackageName;
|
|
459
|
+
exports.moveCompatPackagesToDevDependencies = moveCompatPackagesToDevDependencies;
|
|
409
460
|
exports.normalizeVersion = normalizeVersion;
|
|
410
|
-
exports.
|
|
461
|
+
exports.runPackageInstall = runPackageInstall;
|
|
411
462
|
//# sourceMappingURL=packageManager.cjs.map
|