@jakubmazanec/carson 3.0.6 → 3.0.7-unstable.72f063e3
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/build/commands/create-project/runCreateProject.js.map +2 -2
- package/build/commands/create-workspace/runCreateWorkspace.js.map +2 -2
- package/build/template/TemplateAttributes.js.map +2 -2
- package/build/template/TemplateData.js.map +2 -2
- package/build/template/applyTemplateRenders.d.ts +2 -1
- package/build/template/applyTemplateRenders.js.map +2 -2
- package/build/template/internals/simplify.d.ts +2 -1
- package/build/template/internals/simplify.js.map +2 -2
- package/build/workspace/Project.d.ts +2 -1
- package/build/workspace/Project.js.map +2 -2
- package/build/workspace/Workspace.d.ts +8 -3
- package/build/workspace/Workspace.js +6 -2
- package/build/workspace/Workspace.js.map +2 -2
- package/build/workspace/WorkspaceDependencies.d.ts +4 -2
- package/build/workspace/WorkspaceDependencies.js +2 -1
- package/build/workspace/WorkspaceDependencies.js.map +2 -2
- package/build/workspace/WorkspaceDependenciesFromWorkspaceOptions.d.ts +2 -1
- package/build/workspace/WorkspaceDependency.d.ts +2 -1
- package/build/workspace/WorkspaceDependencyProject.d.ts +1 -1
- package/package.json +8 -8
- package/source/commands/create-project/runCreateProject.ts +2 -1
- package/source/commands/create-workspace/runCreateWorkspace.ts +2 -1
- package/source/template/TemplateAttributes.ts +2 -1
- package/source/template/TemplateData.ts +2 -1
- package/source/template/applyTemplateRenders.ts +2 -1
- package/source/template/internals/simplify.ts +2 -1
- package/source/workspace/Project.ts +6 -3
- package/source/workspace/Workspace.ts +10 -4
- package/source/workspace/WorkspaceDependencies.ts +4 -2
- package/source/workspace/WorkspaceDependenciesFromWorkspaceOptions.ts +2 -1
- package/source/workspace/WorkspaceDependency.ts +2 -1
- package/source/workspace/WorkspaceDependencyProject.ts +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../source/commands/create-project/runCreateProject.ts"],
|
|
4
|
-
"sourcesContent": ["import {type CommandArguments} from '@jakubmazanec/cli';\nimport Observable from 'zen-observable';\n\nimport {type Workspace} from '../../workspace.js';\nimport {type createProjectCommand} from './createProjectCommand.js';\n\nexport type CreateProjectOptions = {\n projectPath: string;\n projectName: string;\n templateId: string;\n workspace: Workspace | Workspace<false>;\n args: CommandArguments<typeof createProjectCommand>;\n};\n\nexport type CreateProjectStatus = string;\n\nexport function runCreateProject({\n projectPath,\n templateId,\n projectName,\n workspace,\n args,\n}: CreateProjectOptions) {\n return new Observable<CreateProjectStatus>((observer) => {\n (async () => {\n observer.next('Creating files');\n\n let project = await workspace.createProject({\n projectPath,\n projectName,\n templateId,\n args,\n });\n\n observer.next('Updating the new project');\n\n // if the project doesn't have config with a template ID, it's on purpose, but it's still needed for the next update, so we'll add it manually\n project.config.template ??= templateId;\n\n await project.update({args});\n })()\n .then(() => {\n observer.complete();\n })\n .catch((error: unknown) => {\n observer.error(error);\n });\n });\n}\n"],
|
|
5
|
-
"mappings": "AACA,OAAO,gBAAgB;AAehB,gBAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACvB,SAAO,IAAI,WAAgC,CAAC,aAAa;AACvD,KAAC,YAAY;AACX,eAAS,KAAK,gBAAgB;AAE9B,UAAI,UAAU,MAAM,UAAU,cAAc;AAAA,QAC1C;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAED,eAAS,KAAK,0BAA0B;
|
|
4
|
+
"sourcesContent": ["import {type CommandArguments} from '@jakubmazanec/cli';\nimport Observable from 'zen-observable';\n\nimport {type Workspace} from '../../workspace.js';\nimport {type createProjectCommand} from './createProjectCommand.js';\n\nexport type CreateProjectOptions = {\n projectPath: string;\n projectName: string;\n templateId: string;\n workspace: Workspace | Workspace<false>;\n args: CommandArguments<typeof createProjectCommand>;\n};\n\nexport type CreateProjectStatus = string;\n\nexport function runCreateProject({\n projectPath,\n templateId,\n projectName,\n workspace,\n args,\n}: CreateProjectOptions) {\n return new Observable<CreateProjectStatus>((observer) => {\n (async () => {\n observer.next('Creating files');\n\n let project = await workspace.createProject({\n projectPath,\n projectName,\n templateId,\n args,\n });\n\n observer.next('Updating the new project');\n\n // if the project doesn't have config with a template ID, it's on purpose, but it's still\n // needed for the next update, so we'll add it manually\n project.config.template ??= templateId;\n\n await project.update({args});\n })()\n .then(() => {\n observer.complete();\n })\n .catch((error: unknown) => {\n observer.error(error);\n });\n });\n}\n"],
|
|
5
|
+
"mappings": "AACA,OAAO,gBAAgB;AAehB,gBAAS,iBAAiB;AAAA,EAC/B;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,GAAyB;AACvB,SAAO,IAAI,WAAgC,CAAC,aAAa;AACvD,KAAC,YAAY;AACX,eAAS,KAAK,gBAAgB;AAE9B,UAAI,UAAU,MAAM,UAAU,cAAc;AAAA,QAC1C;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA,MACF,CAAC;AAED,eAAS,KAAK,0BAA0B;AAIxC,cAAQ,OAAO,aAAa;AAE5B,YAAM,QAAQ,OAAO,EAAC,KAAI,CAAC;AAAA,IAC7B,GAAG,EACA,KAAK,MAAM;AACV,eAAS,SAAS;AAAA,IACpB,CAAC,EACA,MAAM,CAAC,UAAmB;AACzB,eAAS,MAAM,KAAK;AAAA,IACtB,CAAC;AAAA,EACL,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../source/commands/create-workspace/runCreateWorkspace.ts"],
|
|
4
|
-
"sourcesContent": ["import {type CommandArguments} from '@jakubmazanec/cli';\nimport Observable from 'zen-observable';\n\nimport {Workspace} from '../../workspace.js';\nimport {type createWorkspaceCommand} from './createWorkspaceCommand.js';\n\nexport type CreateWorkspaceOptions = {\n workspacePath: string;\n templateId: string;\n args: CommandArguments<typeof createWorkspaceCommand>;\n};\n\nexport type CreateWorkspaceStatus = string;\n\nexport function runCreateWorkspace({workspacePath, templateId, args}: CreateWorkspaceOptions) {\n return new Observable<CreateWorkspaceStatus>((observer) => {\n (async () => {\n observer.next('Creating files');\n\n let workspace = await Workspace.create({\n args,\n path: workspacePath,\n templateId,\n });\n\n observer.next('Updating the new workspace');\n\n // if the workspace doesn't have config with a template ID, it's on purpose, but it's still needed for the next update, so we'll add it manually\n workspace.config.template ??= templateId;\n\n await workspace.update({args});\n })()\n .then(() => {\n observer.complete();\n })\n .catch((error: unknown) => {\n observer.error(error);\n });\n });\n}\n"],
|
|
5
|
-
"mappings": "AACA,OAAO,gBAAgB;AAEvB,SAAQ,iBAAgB;AAWjB,gBAAS,mBAAmB,EAAC,eAAe,YAAY,KAAI,GAA2B;AAC5F,SAAO,IAAI,WAAkC,CAAC,aAAa;AACzD,KAAC,YAAY;AACX,eAAS,KAAK,gBAAgB;AAE9B,UAAI,YAAY,MAAM,UAAU,OAAO;AAAA,QACrC;AAAA,QACA,MAAM;AAAA,QACN;AAAA,MACF,CAAC;AAED,eAAS,KAAK,4BAA4B;
|
|
4
|
+
"sourcesContent": ["import {type CommandArguments} from '@jakubmazanec/cli';\nimport Observable from 'zen-observable';\n\nimport {Workspace} from '../../workspace.js';\nimport {type createWorkspaceCommand} from './createWorkspaceCommand.js';\n\nexport type CreateWorkspaceOptions = {\n workspacePath: string;\n templateId: string;\n args: CommandArguments<typeof createWorkspaceCommand>;\n};\n\nexport type CreateWorkspaceStatus = string;\n\nexport function runCreateWorkspace({workspacePath, templateId, args}: CreateWorkspaceOptions) {\n return new Observable<CreateWorkspaceStatus>((observer) => {\n (async () => {\n observer.next('Creating files');\n\n let workspace = await Workspace.create({\n args,\n path: workspacePath,\n templateId,\n });\n\n observer.next('Updating the new workspace');\n\n // if the workspace doesn't have config with a template ID, it's on purpose, but it's still\n // needed for the next update, so we'll add it manually\n workspace.config.template ??= templateId;\n\n await workspace.update({args});\n })()\n .then(() => {\n observer.complete();\n })\n .catch((error: unknown) => {\n observer.error(error);\n });\n });\n}\n"],
|
|
5
|
+
"mappings": "AACA,OAAO,gBAAgB;AAEvB,SAAQ,iBAAgB;AAWjB,gBAAS,mBAAmB,EAAC,eAAe,YAAY,KAAI,GAA2B;AAC5F,SAAO,IAAI,WAAkC,CAAC,aAAa;AACzD,KAAC,YAAY;AACX,eAAS,KAAK,gBAAgB;AAE9B,UAAI,YAAY,MAAM,UAAU,OAAO;AAAA,QACrC;AAAA,QACA,MAAM;AAAA,QACN;AAAA,MACF,CAAC;AAED,eAAS,KAAK,4BAA4B;AAI1C,gBAAU,OAAO,aAAa;AAE9B,YAAM,UAAU,OAAO,EAAC,KAAI,CAAC;AAAA,IAC/B,GAAG,EACA,KAAK,MAAM;AACV,eAAS,SAAS;AAAA,IACpB,CAAC,EACA,MAAM,CAAC,UAAmB;AACzB,eAAS,MAAM,KAAK;AAAA,IACtB,CAAC;AAAA,EACL,CAAC;AACH;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../source/template/TemplateAttributes.ts"],
|
|
4
|
-
"sourcesContent": ["import {z} from 'zod';\n\n// TODO: add strategy 'none' so when you using template A that extends template B, you can overwrite template files to no-op\nlet strategyTemplateAttributeSchema = z.union([\n z.literal('create'),\n z.literal('ensure'),\n z.literal('overwrite'),\n z.literal('merge'),\n z.literal('check'),\n z.tuple([z.literal('insert'), z.string()]),\n]);\n\nexport const templateAttributesSchema = z\n .object({\n strategy: strategyTemplateAttributeSchema,\n })\n .strict();\n\nexport type TemplateAttributes = z.infer<typeof templateAttributesSchema>;\n"],
|
|
5
|
-
"mappings": "AAAA,SAAQ,SAAQ;
|
|
4
|
+
"sourcesContent": ["import {z} from 'zod';\n\n// TODO: add strategy 'none' so when you using template A that extends template B, you can\n// overwrite template files to no-op\nlet strategyTemplateAttributeSchema = z.union([\n z.literal('create'),\n z.literal('ensure'),\n z.literal('overwrite'),\n z.literal('merge'),\n z.literal('check'),\n z.tuple([z.literal('insert'), z.string()]),\n]);\n\nexport const templateAttributesSchema = z\n .object({\n strategy: strategyTemplateAttributeSchema,\n })\n .strict();\n\nexport type TemplateAttributes = z.infer<typeof templateAttributesSchema>;\n"],
|
|
5
|
+
"mappings": "AAAA,SAAQ,SAAQ;AAIhB,IAAI,kCAAkC,EAAE,MAAM;AAAA,EAC5C,EAAE,QAAQ,QAAQ;AAAA,EAClB,EAAE,QAAQ,QAAQ;AAAA,EAClB,EAAE,QAAQ,WAAW;AAAA,EACrB,EAAE,QAAQ,OAAO;AAAA,EACjB,EAAE,QAAQ,OAAO;AAAA,EACjB,EAAE,MAAM,CAAC,EAAE,QAAQ,QAAQ,GAAG,EAAE,OAAO,CAAC,CAAC;AAC3C,CAAC;AAEM,aAAM,2BAA2B,EACrC,OAAO;AAAA,EACN,UAAU;AACZ,CAAC,EACA,OAAO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../source/template/TemplateData.ts"],
|
|
4
|
-
"sourcesContent": ["import {z} from 'zod';\n\nimport {Project} from '../workspace/Project.js';\nimport {Workspace} from '../workspace/Workspace.js';\n\n// TODO: what about template data for workspace and template data for project, so we can get rid of the `.optional()`?\nexport const templateDataSchema = z\n .object({\n workspace: z.instanceof(Workspace).optional(),\n project: z.instanceof(Project).optional(),\n args: z.record(z.string(), z.unknown()).optional(),\n })\n .strict();\n\nexport type TemplateData = z.infer<typeof templateDataSchema>;\n"],
|
|
5
|
-
"mappings": "AAAA,SAAQ,SAAQ;AAEhB,SAAQ,eAAc;AACtB,SAAQ,iBAAgB;
|
|
4
|
+
"sourcesContent": ["import {z} from 'zod';\n\nimport {Project} from '../workspace/Project.js';\nimport {Workspace} from '../workspace/Workspace.js';\n\n// TODO: what about template data for workspace and template data for project, so we can get rid of\n// the `.optional()`?\nexport const templateDataSchema = z\n .object({\n workspace: z.instanceof(Workspace).optional(),\n project: z.instanceof(Project).optional(),\n args: z.record(z.string(), z.unknown()).optional(),\n })\n .strict();\n\nexport type TemplateData = z.infer<typeof templateDataSchema>;\n"],
|
|
5
|
+
"mappings": "AAAA,SAAQ,SAAQ;AAEhB,SAAQ,eAAc;AACtB,SAAQ,iBAAgB;AAIjB,aAAM,qBAAqB,EAC/B,OAAO;AAAA,EACN,WAAW,EAAE,WAAW,SAAS,EAAE,SAAS;AAAA,EAC5C,SAAS,EAAE,WAAW,OAAO,EAAE,SAAS;AAAA,EACxC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,EAAE,SAAS;AACnD,CAAC,EACA,OAAO;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6,6 +6,7 @@ export type ApplyTemplateRendersOptions = {
|
|
|
6
6
|
ignoreStrategies: string[];
|
|
7
7
|
};
|
|
8
8
|
/**
|
|
9
|
-
* Applies rendered Carson template to a specified path, i.e. creates and updates files based on
|
|
9
|
+
* Applies rendered Carson template to a specified path, i.e. creates and updates files based on
|
|
10
|
+
* the result of rendering each Carson template file.
|
|
10
11
|
*/
|
|
11
12
|
export declare function applyTemplateRenders({ templateRenders, targetPath, snapshotPath, ignoreStrategies, }: ApplyTemplateRendersOptions): Promise<void>;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../source/template/applyTemplateRenders.ts"],
|
|
4
|
-
"sourcesContent": ["import fs from 'fs-extra';\nimport path from 'node:path';\nimport prettier from 'prettier';\n\nimport {CARSON_CONFIG_DIRECTORY} from '../constants.js';\nimport {CarsonTemplateError} from './CarsonTemplateError.js';\nimport {\n createUsingTemplateRender,\n deleteUsingTemplateRenderSnapshot,\n insertUsingTemplateRender,\n loadTemplateRenderSnapshots,\n mergeUsingTemplateRender,\n overwriteUsingTemplateRender,\n saveTemplateRenderSnapshots,\n uninsertUsingTemplateRenderSnapshot,\n unmergeUsingTemplateRenderSnapshot,\n} from './internals.js';\nimport {type TemplateRenders} from './TemplateRenders.js';\n\nexport type ApplyTemplateRendersOptions = {\n templateRenders: TemplateRenders;\n targetPath: string;\n snapshotPath?: string | undefined;\n ignoreStrategies: string[];\n};\n\n/**\n * Applies rendered Carson template to a specified path, i.e. creates and updates files based on the result of rendering each Carson template file.\n */\nexport async function applyTemplateRenders({\n templateRenders,\n targetPath,\n snapshotPath,\n ignoreStrategies,\n}: ApplyTemplateRendersOptions) {\n // we need to clear Prettier cache, because we are changing file system\n await prettier.clearConfigCache();\n\n // first, we read the existing snapshots and use them to undo previous changes\n if (snapshotPath && (await fs.pathExists(snapshotPath))) {\n let templateRenderSnapshots = await loadTemplateRenderSnapshots(snapshotPath);\n\n for (let templateRenderSnapshot of templateRenderSnapshots) {\n let strategy =\n typeof templateRenderSnapshot.attributes.strategy === 'string' ?\n templateRenderSnapshot.attributes.strategy\n : templateRenderSnapshot.attributes.strategy[0];\n\n if (ignoreStrategies.includes(strategy)) {\n continue;\n }\n\n if (templateRenderSnapshot.attributes.strategy === 'ensure') {\n await deleteUsingTemplateRenderSnapshot(templateRenderSnapshot, targetPath, {\n onlyDeleteWhenContentsMatch: true,\n });\n }\n\n if (templateRenderSnapshot.attributes.strategy === 'overwrite') {\n await deleteUsingTemplateRenderSnapshot(templateRenderSnapshot, targetPath);\n }\n\n if (templateRenderSnapshot.attributes.strategy === 'merge') {\n await unmergeUsingTemplateRenderSnapshot(templateRenderSnapshot, targetPath);\n }\n\n if (templateRenderSnapshot.attributes.strategy[0] === 'insert') {\n await uninsertUsingTemplateRenderSnapshot(templateRenderSnapshot, targetPath);\n }\n }\n }\n\n // second, we apply strategies that create files\n for (let templateRender of templateRenders) {\n let strategy =\n typeof templateRender.attributes.strategy === 'string' ?\n templateRender.attributes.strategy\n : templateRender.attributes.strategy[0];\n\n if (ignoreStrategies.includes(strategy)) {\n continue;\n }\n\n if (templateRender.attributes.strategy === 'create') {\n await createUsingTemplateRender(templateRender, targetPath);\n }\n\n if (templateRender.attributes.strategy === 'ensure') {\n let to = path.join(targetPath, templateRender.attributes.to);\n let doesToExist = await fs.pathExists(to);\n\n if (!doesToExist) {\n await createUsingTemplateRender(templateRender, targetPath);\n }\n }\n }\n\n // third, we apply strategies that change files\n for (let templateRender of templateRenders) {\n let strategy =\n typeof templateRender.attributes.strategy === 'string' ?\n templateRender.attributes.strategy\n : templateRender.attributes.strategy[0];\n\n if (ignoreStrategies.includes(strategy)) {\n continue;\n }\n\n if (templateRender.attributes.strategy === 'overwrite') {\n await overwriteUsingTemplateRender(templateRender, targetPath);\n }\n\n if (templateRender.attributes.strategy === 'merge') {\n await mergeUsingTemplateRender(templateRender, targetPath);\n }\n\n if (templateRender.attributes.strategy[0] === 'insert') {\n await insertUsingTemplateRender(templateRender, targetPath);\n }\n\n if (templateRender.attributes.strategy === 'check') {\n let to = path.join(targetPath, templateRender.attributes.to);\n let doesToExist = await fs.pathExists(to);\n\n if (!doesToExist) {\n throw new CarsonTemplateError('STRATEGY_MISSING_FILE', {\n messageParameters: [templateRender.attributes.strategy, templateRender.template.path, to],\n data: {\n path: to,\n },\n });\n }\n }\n }\n\n if (snapshotPath) {\n await fs.ensureDir(path.join(targetPath, CARSON_CONFIG_DIRECTORY));\n\n await saveTemplateRenderSnapshots(templateRenders, snapshotPath);\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,cAAc;AAErB,SAAQ,+BAA8B;AACtC,SAAQ,2BAA0B;AAClC;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;
|
|
4
|
+
"sourcesContent": ["import fs from 'fs-extra';\nimport path from 'node:path';\nimport prettier from 'prettier';\n\nimport {CARSON_CONFIG_DIRECTORY} from '../constants.js';\nimport {CarsonTemplateError} from './CarsonTemplateError.js';\nimport {\n createUsingTemplateRender,\n deleteUsingTemplateRenderSnapshot,\n insertUsingTemplateRender,\n loadTemplateRenderSnapshots,\n mergeUsingTemplateRender,\n overwriteUsingTemplateRender,\n saveTemplateRenderSnapshots,\n uninsertUsingTemplateRenderSnapshot,\n unmergeUsingTemplateRenderSnapshot,\n} from './internals.js';\nimport {type TemplateRenders} from './TemplateRenders.js';\n\nexport type ApplyTemplateRendersOptions = {\n templateRenders: TemplateRenders;\n targetPath: string;\n snapshotPath?: string | undefined;\n ignoreStrategies: string[];\n};\n\n/**\n * Applies rendered Carson template to a specified path, i.e. creates and updates files based on\n * the result of rendering each Carson template file.\n */\nexport async function applyTemplateRenders({\n templateRenders,\n targetPath,\n snapshotPath,\n ignoreStrategies,\n}: ApplyTemplateRendersOptions) {\n // we need to clear Prettier cache, because we are changing file system\n await prettier.clearConfigCache();\n\n // first, we read the existing snapshots and use them to undo previous changes\n if (snapshotPath && (await fs.pathExists(snapshotPath))) {\n let templateRenderSnapshots = await loadTemplateRenderSnapshots(snapshotPath);\n\n for (let templateRenderSnapshot of templateRenderSnapshots) {\n let strategy =\n typeof templateRenderSnapshot.attributes.strategy === 'string' ?\n templateRenderSnapshot.attributes.strategy\n : templateRenderSnapshot.attributes.strategy[0];\n\n if (ignoreStrategies.includes(strategy)) {\n continue;\n }\n\n if (templateRenderSnapshot.attributes.strategy === 'ensure') {\n await deleteUsingTemplateRenderSnapshot(templateRenderSnapshot, targetPath, {\n onlyDeleteWhenContentsMatch: true,\n });\n }\n\n if (templateRenderSnapshot.attributes.strategy === 'overwrite') {\n await deleteUsingTemplateRenderSnapshot(templateRenderSnapshot, targetPath);\n }\n\n if (templateRenderSnapshot.attributes.strategy === 'merge') {\n await unmergeUsingTemplateRenderSnapshot(templateRenderSnapshot, targetPath);\n }\n\n if (templateRenderSnapshot.attributes.strategy[0] === 'insert') {\n await uninsertUsingTemplateRenderSnapshot(templateRenderSnapshot, targetPath);\n }\n }\n }\n\n // second, we apply strategies that create files\n for (let templateRender of templateRenders) {\n let strategy =\n typeof templateRender.attributes.strategy === 'string' ?\n templateRender.attributes.strategy\n : templateRender.attributes.strategy[0];\n\n if (ignoreStrategies.includes(strategy)) {\n continue;\n }\n\n if (templateRender.attributes.strategy === 'create') {\n await createUsingTemplateRender(templateRender, targetPath);\n }\n\n if (templateRender.attributes.strategy === 'ensure') {\n let to = path.join(targetPath, templateRender.attributes.to);\n let doesToExist = await fs.pathExists(to);\n\n if (!doesToExist) {\n await createUsingTemplateRender(templateRender, targetPath);\n }\n }\n }\n\n // third, we apply strategies that change files\n for (let templateRender of templateRenders) {\n let strategy =\n typeof templateRender.attributes.strategy === 'string' ?\n templateRender.attributes.strategy\n : templateRender.attributes.strategy[0];\n\n if (ignoreStrategies.includes(strategy)) {\n continue;\n }\n\n if (templateRender.attributes.strategy === 'overwrite') {\n await overwriteUsingTemplateRender(templateRender, targetPath);\n }\n\n if (templateRender.attributes.strategy === 'merge') {\n await mergeUsingTemplateRender(templateRender, targetPath);\n }\n\n if (templateRender.attributes.strategy[0] === 'insert') {\n await insertUsingTemplateRender(templateRender, targetPath);\n }\n\n if (templateRender.attributes.strategy === 'check') {\n let to = path.join(targetPath, templateRender.attributes.to);\n let doesToExist = await fs.pathExists(to);\n\n if (!doesToExist) {\n throw new CarsonTemplateError('STRATEGY_MISSING_FILE', {\n messageParameters: [templateRender.attributes.strategy, templateRender.template.path, to],\n data: {\n path: to,\n },\n });\n }\n }\n }\n\n if (snapshotPath) {\n await fs.ensureDir(path.join(targetPath, CARSON_CONFIG_DIRECTORY));\n\n await saveTemplateRenderSnapshots(templateRenders, snapshotPath);\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,QAAQ;AACf,OAAO,UAAU;AACjB,OAAO,cAAc;AAErB,SAAQ,+BAA8B;AACtC,SAAQ,2BAA0B;AAClC;AAAA,EACE;AAAA,EACA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for usage in snapshots: string, number or boolean values are replaced with
|
|
3
|
+
* `null`.
|
|
3
4
|
*/
|
|
4
5
|
export declare function simplify(a: unknown): Record<string, unknown> | null;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../source/template/internals/simplify.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Simplifies JSON for usage in snapshots: string, number or boolean values are replaced with `null`.\n */\nexport function simplify(a: unknown) {\n if (a === undefined || a == null) {\n return null;\n }\n\n if (typeof a !== 'object' || Array.isArray(a)) {\n return null;\n }\n\n const newA: Record<string, unknown> = {...a};\n\n for (let [key] of Object.entries(a)) {\n if (\n (a as Record<string, unknown>)[key] &&\n typeof (a as Record<string, unknown>)[key] === 'object' &&\n !Array.isArray((a as Record<string, unknown>)[key])\n ) {\n const result = simplify((a as Record<string, unknown>)[key]);\n\n newA[key] = result;\n } else {\n newA[key] = null;\n }\n }\n\n return newA;\n}\n"],
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["/**\n * Simplifies JSON for usage in snapshots: string, number or boolean values are replaced with\n * `null`.\n */\nexport function simplify(a: unknown) {\n if (a === undefined || a == null) {\n return null;\n }\n\n if (typeof a !== 'object' || Array.isArray(a)) {\n return null;\n }\n\n const newA: Record<string, unknown> = {...a};\n\n for (let [key] of Object.entries(a)) {\n if (\n (a as Record<string, unknown>)[key] &&\n typeof (a as Record<string, unknown>)[key] === 'object' &&\n !Array.isArray((a as Record<string, unknown>)[key])\n ) {\n const result = simplify((a as Record<string, unknown>)[key]);\n\n newA[key] = result;\n } else {\n newA[key] = null;\n }\n }\n\n return newA;\n}\n"],
|
|
5
|
+
"mappings": "AAIO,gBAAS,SAAS,GAAY;AACnC,MAAI,MAAM,UAAa,KAAK,MAAM;AAChC,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,MAAM,YAAY,MAAM,QAAQ,CAAC,GAAG;AAC7C,WAAO;AAAA,EACT;AAEA,QAAM,OAAgC,EAAC,GAAG,EAAC;AAE3C,WAAS,CAAC,GAAG,KAAK,OAAO,QAAQ,CAAC,GAAG;AACnC,QACG,EAA8B,GAAG,KAClC,OAAQ,EAA8B,GAAG,MAAM,YAC/C,CAAC,MAAM,QAAS,EAA8B,GAAG,CAAC,GAClD;AACA,YAAM,SAAS,SAAU,EAA8B,GAAG,CAAC;AAE3D,WAAK,GAAG,IAAI;AAAA,IACd,OAAO;AACL,WAAK,GAAG,IAAI;AAAA,IACd;AAAA,EACF;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -6,7 +6,8 @@ import { type ProjectOptions } from './ProjectOptions.js';
|
|
|
6
6
|
import { type ProjectUpdateOptions } from './ProjectUpdateOptions.js';
|
|
7
7
|
import { type Workspace } from './Workspace.js';
|
|
8
8
|
/**
|
|
9
|
-
* Project represent a self-contained piece of software (e.g. a package, or an app) that is part of
|
|
9
|
+
* Project represent a self-contained piece of software (e.g. a package, or an app) that is part of
|
|
10
|
+
* a {@link Workspace}. Currently only Node.js projects are supported.
|
|
10
11
|
*
|
|
11
12
|
* @typeParam M If true, the project belongs to a multi-project workspace.
|
|
12
13
|
*/
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../source/workspace/Project.ts"],
|
|
4
|
-
"sourcesContent": ["import {ensureEmptyDirectory, pathToPosixPath} from '@jakubmazanec/fs-utils';\nimport {type PackageJson, packageJsonSchema, readFile} from '@jakubmazanec/zod-utils';\nimport fs from 'fs-extra';\nimport json5 from 'json5';\nimport path from 'node:path';\nimport {z} from 'zod';\n\nimport {\n CARSON_CONFIG_DIRECTORY,\n PROJECT_CONFIG_FILENAME,\n PROJECT_SNAPSHOT_FILENAME,\n} from '../constants.js';\nimport {applyTemplateRenders} from '../template/applyTemplateRenders.js';\nimport {readCarsonTemplate} from '../template/internals.js';\nimport {renderCarsonTemplate} from '../template/renderCarsonTemplate.js';\nimport {type ProjectConfig, projectConfigSchema} from './ProjectConfig.js';\nimport {type ProjectCreateOptions} from './ProjectCreateOptions.js';\nimport {ProjectError} from './ProjectError.js';\nimport {type ProjectOptions} from './ProjectOptions.js';\nimport {type ProjectUpdateOptions} from './ProjectUpdateOptions.js';\nimport {saveProjectConfig} from './saveProjectConfig.js';\nimport {type Workspace} from './Workspace.js';\n\n/**\n * Project represent a self-contained piece of software (e.g. a package, or an app) that is part of a {@link Workspace}. Currently only Node.js projects are supported.\n *\n * @typeParam M If true, the project belongs to a multi-project workspace.\n */\nexport class Project<M extends boolean = true> {\n /** Project name. */\n name?: string;\n\n /** Project path. */\n path: string;\n\n /** Project path relative to workspace path. */\n relativePath: string;\n\n /** Project configuration; if it's not found, the default is an empty object. */\n config: ProjectConfig;\n\n /** Parsed project `package.json` file; if it's not found, the default is an empty object. */\n packageJson: PackageJson;\n\n /** Parent {@link Workspace} instance. */\n workspace: Workspace<M>;\n\n /** Errors found during reading from the file system. */\n errors: Array<InstanceType<typeof ProjectError>> = [];\n\n constructor({\n path: projectPath,\n name,\n config,\n packageJson,\n workspace,\n errors,\n }: ProjectOptions<M>) {\n // TODO: check that this path and workspace path are correct, i.e. project path must always be inside of workspace path\n this.path = projectPath;\n\n if (name) {\n this.name = name;\n }\n\n if (config) {\n this.config = config;\n } else {\n this.config = {};\n }\n\n if (packageJson) {\n this.packageJson = packageJson;\n } else {\n this.packageJson = {};\n }\n\n this.workspace = workspace;\n\n if (errors) {\n this.errors = errors;\n }\n\n if (this.packageJson.name?.length) {\n this.name = this.packageJson.name;\n }\n\n this.relativePath = pathToPosixPath(path.relative(this.workspace.path, this.path));\n }\n\n static async create<M extends boolean>({\n templateId,\n workspace,\n projectPath,\n projectName,\n args,\n }: ProjectCreateOptions<M>): Promise<Project<M>> {\n let project = new this({\n path: projectPath,\n name: projectName,\n config: {\n template: templateId,\n },\n workspace,\n });\n\n // if the workspace is single-project, it shares a directory with the project, so we can't insist on it being an empty directory\n if (workspace.isMultiProject) {\n try {\n await ensureEmptyDirectory(project.path);\n } catch {\n throw new ProjectError('PROJECT_PATH_NOT_EMPTY', {\n messageParameters: [project.path],\n data: {\n path: project.path,\n },\n });\n }\n }\n\n let template = await readCarsonTemplate(templateId);\n let templateRenders = await renderCarsonTemplate({\n template,\n templateData: {\n workspace,\n project,\n args,\n },\n });\n\n if (!template.config.autoEject && workspace.config.template) {\n await saveProjectConfig({projectPath: project.path, projectConfig: {template: templateId}});\n }\n\n await applyTemplateRenders({\n templateRenders,\n targetPath: project.path,\n snapshotPath:\n template.config.autoEject || !workspace.config.template ?\n undefined\n : path.join(project.path, CARSON_CONFIG_DIRECTORY, PROJECT_SNAPSHOT_FILENAME),\n ignoreStrategies: ['check'],\n });\n\n await project.read();\n\n return project;\n }\n\n static async read<M extends boolean>(\n projectPath: string,\n workspace: Workspace<M>,\n ): Promise<Project<M>> {\n let project = new this({\n path: projectPath,\n workspace,\n });\n\n await project.read();\n\n return project;\n }\n\n async read() {\n if (!(await fs.pathExists(this.path))) {\n throw new ProjectError('NO_SUCH_PROJECT_PATH', {\n messageParameters: [this.path],\n data: {\n path: this.path,\n },\n });\n }\n\n let errors: Array<InstanceType<typeof ProjectError>> = [];\n\n // load project config\n let projectConfigPath = path.join(this.path, CARSON_CONFIG_DIRECTORY, PROJECT_CONFIG_FILENAME);\n let doesProjectConfigExist = await fs.pathExists(projectConfigPath);\n let projectConfig: ProjectConfig | z.ZodError;\n\n if (doesProjectConfigExist) {\n projectConfig = await readFile(projectConfigPath, projectConfigSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n } else {\n projectConfig = {};\n }\n\n if (projectConfig instanceof z.ZodError) {\n let zodError = projectConfig;\n\n errors.push(\n new ProjectError('INVALID_PROJECT_CONFIG', {\n messageParameters: [projectConfigPath],\n data: {\n path: projectConfigPath,\n zodIssues: zodError.issues,\n },\n }),\n );\n\n projectConfig = {};\n }\n\n // load package.json\n let packageJsonPath = path.join(this.path, 'package.json');\n let doesPackageJsonExist = await fs.pathExists(packageJsonPath);\n let packageJson: PackageJson | z.ZodError;\n\n if (doesPackageJsonExist) {\n packageJson = await readFile(packageJsonPath, packageJsonSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n } else {\n packageJson = {};\n }\n\n if (packageJson instanceof z.ZodError) {\n let zodError = packageJson;\n\n errors.push(\n new ProjectError('INVALID_PACKAGE_JSON', {\n messageParameters: [packageJsonPath],\n data: {\n path: packageJsonPath,\n zodIssues: zodError.issues,\n },\n }),\n );\n\n packageJson = {};\n }\n\n if (packageJson.name?.length) {\n this.name = packageJson.name;\n }\n\n this.config = projectConfig;\n this.packageJson = packageJson;\n this.errors = errors;\n\n return this;\n }\n\n async update({args}: ProjectUpdateOptions): Promise<this> {\n if (!this.config.template) {\n throw new ProjectError('MISSING_CARSON_TEMPLATE_ID', {\n messageParameters: [path.join(this.path, CARSON_CONFIG_DIRECTORY, PROJECT_CONFIG_FILENAME)],\n });\n }\n\n let template = await readCarsonTemplate(this.config.template);\n let templateRenders = await renderCarsonTemplate({\n template,\n templateData: {\n workspace: this.workspace,\n project: this,\n args,\n },\n });\n\n await applyTemplateRenders({\n templateRenders,\n targetPath: this.path,\n snapshotPath:\n template.config.autoEject || !this.workspace.config.template ?\n undefined\n : path.join(this.path, CARSON_CONFIG_DIRECTORY, PROJECT_SNAPSHOT_FILENAME),\n ignoreStrategies: ['create'],\n });\n\n await this.read();\n\n return this;\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAQ,sBAAsB,uBAAsB;AACpD,SAA0B,mBAAmB,gBAAe;AAC5D,OAAO,QAAQ;AACf,OAAO,WAAW;AAClB,OAAO,UAAU;AACjB,SAAQ,SAAQ;AAEhB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAQ,4BAA2B;AACnC,SAAQ,0BAAyB;AACjC,SAAQ,4BAA2B;AACnC,SAA4B,2BAA0B;AAEtD,SAAQ,oBAAmB;AAG3B,SAAQ,yBAAwB;
|
|
4
|
+
"sourcesContent": ["import {ensureEmptyDirectory, pathToPosixPath} from '@jakubmazanec/fs-utils';\nimport {type PackageJson, packageJsonSchema, readFile} from '@jakubmazanec/zod-utils';\nimport fs from 'fs-extra';\nimport json5 from 'json5';\nimport path from 'node:path';\nimport {z} from 'zod';\n\nimport {\n CARSON_CONFIG_DIRECTORY,\n PROJECT_CONFIG_FILENAME,\n PROJECT_SNAPSHOT_FILENAME,\n} from '../constants.js';\nimport {applyTemplateRenders} from '../template/applyTemplateRenders.js';\nimport {readCarsonTemplate} from '../template/internals.js';\nimport {renderCarsonTemplate} from '../template/renderCarsonTemplate.js';\nimport {type ProjectConfig, projectConfigSchema} from './ProjectConfig.js';\nimport {type ProjectCreateOptions} from './ProjectCreateOptions.js';\nimport {ProjectError} from './ProjectError.js';\nimport {type ProjectOptions} from './ProjectOptions.js';\nimport {type ProjectUpdateOptions} from './ProjectUpdateOptions.js';\nimport {saveProjectConfig} from './saveProjectConfig.js';\nimport {type Workspace} from './Workspace.js';\n\n/**\n * Project represent a self-contained piece of software (e.g. a package, or an app) that is part of\n * a {@link Workspace}. Currently only Node.js projects are supported.\n *\n * @typeParam M If true, the project belongs to a multi-project workspace.\n */\nexport class Project<M extends boolean = true> {\n /** Project name. */\n name?: string;\n\n /** Project path. */\n path: string;\n\n /** Project path relative to workspace path. */\n relativePath: string;\n\n /** Project configuration; if it's not found, the default is an empty object. */\n config: ProjectConfig;\n\n /** Parsed project `package.json` file; if it's not found, the default is an empty object. */\n packageJson: PackageJson;\n\n /** Parent {@link Workspace} instance. */\n workspace: Workspace<M>;\n\n /** Errors found during reading from the file system. */\n errors: Array<InstanceType<typeof ProjectError>> = [];\n\n constructor({\n path: projectPath,\n name,\n config,\n packageJson,\n workspace,\n errors,\n }: ProjectOptions<M>) {\n // TODO: check that this path and workspace path are correct, i.e. project path must always be\n // inside of workspace path\n this.path = projectPath;\n\n if (name) {\n this.name = name;\n }\n\n if (config) {\n this.config = config;\n } else {\n this.config = {};\n }\n\n if (packageJson) {\n this.packageJson = packageJson;\n } else {\n this.packageJson = {};\n }\n\n this.workspace = workspace;\n\n if (errors) {\n this.errors = errors;\n }\n\n if (this.packageJson.name?.length) {\n this.name = this.packageJson.name;\n }\n\n this.relativePath = pathToPosixPath(path.relative(this.workspace.path, this.path));\n }\n\n static async create<M extends boolean>({\n templateId,\n workspace,\n projectPath,\n projectName,\n args,\n }: ProjectCreateOptions<M>): Promise<Project<M>> {\n let project = new this({\n path: projectPath,\n name: projectName,\n config: {\n template: templateId,\n },\n workspace,\n });\n\n // if the workspace is single-project, it shares a directory with the project, so we can't\n // insist on it being an empty directory\n if (workspace.isMultiProject) {\n try {\n await ensureEmptyDirectory(project.path);\n } catch {\n throw new ProjectError('PROJECT_PATH_NOT_EMPTY', {\n messageParameters: [project.path],\n data: {\n path: project.path,\n },\n });\n }\n }\n\n let template = await readCarsonTemplate(templateId);\n let templateRenders = await renderCarsonTemplate({\n template,\n templateData: {\n workspace,\n project,\n args,\n },\n });\n\n if (!template.config.autoEject && workspace.config.template) {\n await saveProjectConfig({projectPath: project.path, projectConfig: {template: templateId}});\n }\n\n await applyTemplateRenders({\n templateRenders,\n targetPath: project.path,\n snapshotPath:\n template.config.autoEject || !workspace.config.template ?\n undefined\n : path.join(project.path, CARSON_CONFIG_DIRECTORY, PROJECT_SNAPSHOT_FILENAME),\n ignoreStrategies: ['check'],\n });\n\n await project.read();\n\n return project;\n }\n\n static async read<M extends boolean>(\n projectPath: string,\n workspace: Workspace<M>,\n ): Promise<Project<M>> {\n let project = new this({\n path: projectPath,\n workspace,\n });\n\n await project.read();\n\n return project;\n }\n\n async read() {\n if (!(await fs.pathExists(this.path))) {\n throw new ProjectError('NO_SUCH_PROJECT_PATH', {\n messageParameters: [this.path],\n data: {\n path: this.path,\n },\n });\n }\n\n let errors: Array<InstanceType<typeof ProjectError>> = [];\n\n // load project config\n let projectConfigPath = path.join(this.path, CARSON_CONFIG_DIRECTORY, PROJECT_CONFIG_FILENAME);\n let doesProjectConfigExist = await fs.pathExists(projectConfigPath);\n let projectConfig: ProjectConfig | z.ZodError;\n\n if (doesProjectConfigExist) {\n projectConfig = await readFile(projectConfigPath, projectConfigSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n } else {\n projectConfig = {};\n }\n\n if (projectConfig instanceof z.ZodError) {\n let zodError = projectConfig;\n\n errors.push(\n new ProjectError('INVALID_PROJECT_CONFIG', {\n messageParameters: [projectConfigPath],\n data: {\n path: projectConfigPath,\n zodIssues: zodError.issues,\n },\n }),\n );\n\n projectConfig = {};\n }\n\n // load package.json\n let packageJsonPath = path.join(this.path, 'package.json');\n let doesPackageJsonExist = await fs.pathExists(packageJsonPath);\n let packageJson: PackageJson | z.ZodError;\n\n if (doesPackageJsonExist) {\n packageJson = await readFile(packageJsonPath, packageJsonSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n } else {\n packageJson = {};\n }\n\n if (packageJson instanceof z.ZodError) {\n let zodError = packageJson;\n\n errors.push(\n new ProjectError('INVALID_PACKAGE_JSON', {\n messageParameters: [packageJsonPath],\n data: {\n path: packageJsonPath,\n zodIssues: zodError.issues,\n },\n }),\n );\n\n packageJson = {};\n }\n\n if (packageJson.name?.length) {\n this.name = packageJson.name;\n }\n\n this.config = projectConfig;\n this.packageJson = packageJson;\n this.errors = errors;\n\n return this;\n }\n\n async update({args}: ProjectUpdateOptions): Promise<this> {\n if (!this.config.template) {\n throw new ProjectError('MISSING_CARSON_TEMPLATE_ID', {\n messageParameters: [path.join(this.path, CARSON_CONFIG_DIRECTORY, PROJECT_CONFIG_FILENAME)],\n });\n }\n\n let template = await readCarsonTemplate(this.config.template);\n let templateRenders = await renderCarsonTemplate({\n template,\n templateData: {\n workspace: this.workspace,\n project: this,\n args,\n },\n });\n\n await applyTemplateRenders({\n templateRenders,\n targetPath: this.path,\n snapshotPath:\n template.config.autoEject || !this.workspace.config.template ?\n undefined\n : path.join(this.path,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A,YACN,WAAW,SAAS;AAAA,UACtB;AAAA,QACF,CAAC;AAAA,MACH;AAEA,oBAAc,CAAC;AAAA,IACjB;AAEA,QAAI,YAAY,MAAM,QAAQ;AAC5B,WAAK,OAAO,YAAY;AAAA,IAC1B;AAEA,SAAK,SAAS;AACd,SAAK,cAAc;AACnB,SAAK,SAAS;AAEd,WAAO;AAAA,EACT;AAAA,EAEA,MAAM,OAAO,EAAC,KAAI,GAAwC;AACxD,QAAI,CAAC,KAAK,OAAO,UAAU;AACzB,YAAM,IAAI,aAAa,8BAA8B;AAAA,QACnD,mBAAmB,CAAC,KAAK,KAAK,KAAK,MAAM,yBAAyB,uBAAuB,CAAC;AAAA,MAC5F,CAAC;AAAA,IACH;AAEA,QAAI,WAAW,MAAM,mBAAmB,KAAK,OAAO,QAAQ;AAC5D,QAAI,kBAAkB,MAAM,qBAAqB;AAAA,MAC/C;AAAA,MACA,cAAc;AAAA,QACZ,WAAW,KAAK;AAAA,QAChB,SAAS;AAAA,QACT;AAAA,MACF;AAAA,IACF,CAAC;AAED,UAAM,qBAAqB;AAAA,MACzB;AAAA,MACA,YAAY,KAAK;AAAA,MACjB,cACE,SAAS,OAAO,aAAa,CAAC,KAAK,UAAU,OAAO,WAClD,SACA,KAAK,KAAK,KAAK,MAAM,yBAAyB,yBAAyB;AAAA,MAC3E,kBAAkB,CAAC,QAAQ;AAAA,IAC7B,CAAC;AAED,UAAM,KAAK,KAAK;AAEhB,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -12,7 +12,8 @@ import { type WorkspaceProjects } from './WorkspaceProjects.js';
|
|
|
12
12
|
import { type WorkspaceRepository } from './WorkspaceRepository.js';
|
|
13
13
|
import { type WorkspaceUpdateOptions } from './WorkspaceUpdateOptions.js';
|
|
14
14
|
/**
|
|
15
|
-
* Workspace represent a directory, usually a git repository, that contains {@link Project}
|
|
15
|
+
* Workspace represent a directory, usually a git repository, that contains {@link Project}
|
|
16
|
+
* instances.
|
|
16
17
|
*
|
|
17
18
|
* @typeParam M If true, the workspace is multi-project workspace (so-called "monorepo").
|
|
18
19
|
*/
|
|
@@ -27,7 +28,10 @@ export declare class Workspace<M extends boolean = true> {
|
|
|
27
28
|
projects: WorkspaceProjects<M>;
|
|
28
29
|
/** Workspace configuration; if it's not found, the default is an empty object. */
|
|
29
30
|
config: WorkspaceConfig;
|
|
30
|
-
/**
|
|
31
|
+
/**
|
|
32
|
+
* Parsed workspace `package.json` file (if the workspace contains multiple projects); if it's
|
|
33
|
+
* not found, the default is an empty object.
|
|
34
|
+
*/
|
|
31
35
|
packageJson: WorkspacePackageJson<M>;
|
|
32
36
|
/** Workspace git repository. */
|
|
33
37
|
repository?: WorkspaceRepository;
|
|
@@ -51,7 +55,8 @@ export declare class Workspace<M extends boolean = true> {
|
|
|
51
55
|
static create({ args, path: workspacePath, templateId }: WorkspaceCreateOptions): Promise<Workspace<true> | Workspace<false>>;
|
|
52
56
|
static read(workspacePath: string): Promise<Workspace | Workspace<false>>;
|
|
53
57
|
/**
|
|
54
|
-
* Traverses file system up from the search path and tries to find a directory that is a root of
|
|
58
|
+
* Traverses file system up from the search path and tries to find a directory that is a root of
|
|
59
|
+
* a workspace.
|
|
55
60
|
*
|
|
56
61
|
* @param searchPath Search path.
|
|
57
62
|
* @returns Workspace path, if found.
|
|
@@ -39,7 +39,10 @@ export class Workspace {
|
|
|
39
39
|
projects;
|
|
40
40
|
/** Workspace configuration; if it's not found, the default is an empty object. */
|
|
41
41
|
config;
|
|
42
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Parsed workspace `package.json` file (if the workspace contains multiple projects); if it's
|
|
44
|
+
* not found, the default is an empty object.
|
|
45
|
+
*/
|
|
43
46
|
packageJson;
|
|
44
47
|
/** Workspace git repository. */
|
|
45
48
|
repository;
|
|
@@ -233,7 +236,8 @@ export class Workspace {
|
|
|
233
236
|
return workspace;
|
|
234
237
|
}
|
|
235
238
|
/**
|
|
236
|
-
* Traverses file system up from the search path and tries to find a directory that is a root of
|
|
239
|
+
* Traverses file system up from the search path and tries to find a directory that is a root of
|
|
240
|
+
* a workspace.
|
|
237
241
|
*
|
|
238
242
|
* @param searchPath Search path.
|
|
239
243
|
* @returns Workspace path, if found.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../source/workspace/Workspace.ts"],
|
|
4
|
-
"sourcesContent": ["import {ensureEmptyDirectory, findExistingDirectory, isRootPath} from '@jakubmazanec/fs-utils';\nimport {jsonSchema, type PackageJson, packageJsonSchema, readFile} from '@jakubmazanec/zod-utils';\nimport glob from 'fast-glob';\nimport fs from 'fs-extra';\nimport json5 from 'json5';\nimport _ from 'lodash';\nimport path from 'node:path';\nimport {z} from 'zod';\n\nimport {\n CARSON_CONFIG_DIRECTORY,\n PACKAGE_JSON_FILENAME,\n WORKSPACE_CONFIG_FILENAME,\n WORKSPACE_SNAPSHOT_FILENAME,\n} from '../constants.js';\nimport {applyTemplateRenders} from '../template/applyTemplateRenders.js';\nimport {readCarsonTemplate} from '../template/internals.js';\nimport {renderCarsonTemplate} from '../template/renderCarsonTemplate.js';\nimport {\n compareProjectPath,\n containsProject,\n containsWorkspace,\n getPackageJsonWorkspaces,\n getRepositoryBranches,\n getRepositoryUrl,\n} from './internals.js';\nimport {Project} from './Project.js';\nimport {saveWorkspaceConfig} from './saveWorkspaceConfig.js';\nimport {workspaceConfigSchema} from './WorkspaceConfig.js';\nimport {type WorkspaceConfig} from './WorkspaceConfig.js';\nimport {type WorkspaceCreateOptions} from './WorkspaceCreateOptions.js';\nimport {type WorkspaceCreateProjectOptions} from './WorkspaceCreateProjectOptions.js';\nimport {WorkspaceDependencies} from './WorkspaceDependencies.js';\nimport {WorkspaceError} from './WorkspaceError.js';\nimport {type WorkspaceFindAndReadOptions} from './WorkspaceFindAndReadOptions.js';\nimport {type WorkspaceOptions} from './WorkspaceOptions.js';\nimport {type WorkspacePackageJson} from './WorkspacePackageJson.js';\nimport {type WorkspaceProjectGlobs} from './WorkspaceProjectGlobs.js';\nimport {type WorkspaceProjects} from './WorkspaceProjects.js';\nimport {type WorkspaceRepository} from './WorkspaceRepository.js';\nimport {type WorkspaceUpdateOptions} from './WorkspaceUpdateOptions.js';\n\n/**\n * Workspace represent a directory, usually a git repository, that contains {@link Project} instances.\n *\n * @typeParam M If true, the workspace is multi-project workspace (so-called \"monorepo\").\n */\nexport class Workspace<M extends boolean = true> {\n /** Workspace path. */\n readonly path: string;\n\n /** Does the workspace contain a multiple projects? */\n readonly isMultiProject: M;\n\n /** Globs used to find projects. */\n projectGlobs: WorkspaceProjectGlobs<M>;\n\n /** Workspace projects. */\n projects: WorkspaceProjects<M>;\n\n /** Workspace configuration; if it's not found, the default is an empty object. */\n config: WorkspaceConfig;\n\n /** Parsed workspace `package.json` file (if the workspace contains multiple projects); if it's not found, the default is an empty object. */\n packageJson: WorkspacePackageJson<M>;\n\n /** Workspace git repository. */\n repository?: WorkspaceRepository;\n\n /** Dependencies of all projects. */\n dependencies: WorkspaceDependencies<M> = [] as unknown as WorkspaceDependencies<M>;\n\n /** Development dependencies of all projects. */\n devDependencies: WorkspaceDependencies<M> = [] as unknown as WorkspaceDependencies<M>;\n\n /** All dependencies of all projects and workspace dependencies. */\n allDependencies: WorkspaceDependencies<M> = [] as unknown as WorkspaceDependencies<M>;\n\n /** Versions of each dependency. */\n dependencyVersions: Record<string, string[]> = {};\n\n /** Errors found during reading from the file system. */\n errors: Array<InstanceType<typeof WorkspaceError>> = [];\n\n constructor(options: WorkspaceOptions<M>) {\n this.path = options.path;\n\n if (options.isMultiProject === undefined || options.isMultiProject) {\n this.isMultiProject = true as M;\n\n let projectGlobOption = (options as WorkspaceOptions<true>).projectGlobs;\n\n if (projectGlobOption) {\n this.projectGlobs = projectGlobOption as WorkspaceProjectGlobs<M>;\n } else {\n this.projectGlobs = [] as string[] as WorkspaceProjectGlobs<M>;\n }\n\n this.projects = [] as Array<Project<M>>;\n\n let {projects} = options as WorkspaceOptions<true>;\n\n if (projects) {\n this.addProjects(projects.map((project) => new Project({...project, workspace: this})));\n }\n\n let packageJsonOption = (options as WorkspaceOptions<true>).packageJson;\n\n if (packageJsonOption) {\n this.packageJson = packageJsonOption as M extends true ? PackageJson : null;\n } else {\n let emptyPackageJson: PackageJson = {};\n\n this.packageJson = emptyPackageJson as M extends true ? PackageJson : null;\n }\n } else {\n this.isMultiProject = false as M;\n this.projectGlobs = null as M extends true ? string[] : null;\n this.packageJson = null as M extends true ? PackageJson : null;\n this.projects = [] as Array<Project<M>>;\n\n let {projects} = options as WorkspaceOptions<false>;\n\n if (projects) {\n this.addProjects(projects.map((project) => new Project({...project, workspace: this})));\n }\n }\n\n let configOption = options.config;\n\n if (configOption) {\n this.config = configOption;\n } else {\n let emptyWorkspaceConfig: WorkspaceConfig = {};\n\n this.config = emptyWorkspaceConfig;\n }\n\n if (options.repository) {\n this.repository = options.repository;\n }\n\n if (options.errors) {\n this.errors = options.errors;\n }\n\n // add missing project globs\n if (this.isMultiProject && !(this.projectGlobs as string[]).length) {\n let packageJsonWorkspaces = getPackageJsonWorkspaces(this.packageJson);\n\n if (packageJsonWorkspaces) {\n this.projectGlobs = [...packageJsonWorkspaces] as M extends true ? string[] : null;\n }\n }\n\n this.sortProjects();\n this.updateDependencies();\n }\n\n /**\n * Creates new workspace within the file system.\n *\n * @param options Options.\n * @returns The new workspace.\n */\n static async create({args, path: workspacePath, templateId}: WorkspaceCreateOptions) {\n // TODO: test that workspace returned by this method has the same value of isMultiProject when the same workspace is after its creation re-read with .read()\n let workspace = new this({\n path: workspacePath,\n config: {\n template: templateId,\n },\n });\n\n try {\n await ensureEmptyDirectory(workspace.path, {allowGit: true});\n } catch {\n throw new WorkspaceError('WORKSPACE_PATH_NOT_EMPTY', {\n messageParameters: [workspace.path],\n data: {\n path: workspace.path,\n },\n });\n }\n\n let template = await readCarsonTemplate(templateId);\n let templateRenders = await renderCarsonTemplate({\n template,\n templateData: {\n workspace,\n args,\n },\n });\n\n if (!template.config.autoEject) {\n await saveWorkspaceConfig({\n workspacePath: workspace.path,\n workspaceConfig: {template: templateId},\n });\n }\n\n await applyTemplateRenders({\n templateRenders,\n targetPath: workspace.path,\n snapshotPath:\n template.config.autoEject ?\n undefined\n : path.join(workspace.path, CARSON_CONFIG_DIRECTORY, WORKSPACE_SNAPSHOT_FILENAME),\n ignoreStrategies: ['check'],\n });\n\n return Workspace.read(workspace.path);\n }\n\n static async read(workspacePath: string): Promise<Workspace | Workspace<false>> {\n let resolvedWorkspacePath = path.resolve(workspacePath);\n\n if (!(await fs.pathExists(resolvedWorkspacePath))) {\n throw new WorkspaceError('NO_SUCH_WORKSPACE_PATH', {\n messageParameters: [resolvedWorkspacePath],\n data: {\n path: resolvedWorkspacePath,\n },\n });\n }\n\n // load root package.json\n let rootPackageJsonPath = path.join(resolvedWorkspacePath, 'package.json');\n let doesRootPackageJsonExist = await fs.pathExists(rootPackageJsonPath);\n let rootPackageJson: PackageJson | z.ZodError;\n\n if (doesRootPackageJsonExist) {\n rootPackageJson = await readFile(rootPackageJsonPath, packageJsonSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n } else {\n rootPackageJson = {};\n }\n\n if (rootPackageJson instanceof z.ZodError) {\n rootPackageJson = {};\n\n // even if the package.json file has errors, maybe there's still a correct workspace field\n try {\n let rootJson = await readFile(rootPackageJsonPath, jsonSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n throwOnZodError: true,\n });\n let projectGlobs = getPackageJsonWorkspaces(rootJson);\n\n // add back to the empty package.json object\n if (projectGlobs) {\n rootPackageJson.workspaces = projectGlobs;\n }\n } catch {\n // no-op\n }\n }\n\n // load workspace config\n let workspaceConfigPath = path.join(\n resolvedWorkspacePath,\n CARSON_CONFIG_DIRECTORY,\n WORKSPACE_CONFIG_FILENAME,\n );\n let doesWorkspaceConfigExist = await fs.pathExists(workspaceConfigPath);\n let workspaceConfig: WorkspaceConfig | z.ZodError;\n\n if (doesWorkspaceConfigExist) {\n workspaceConfig = await readFile(workspaceConfigPath, workspaceConfigSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n } else {\n workspaceConfig = {};\n }\n\n if (workspaceConfig instanceof z.ZodError) {\n workspaceConfig = {};\n }\n\n // how to find projects\n let packageJsonProjectGlobs = getPackageJsonWorkspaces(rootPackageJson);\n let workspaceConfigProjectGlobs = workspaceConfig.projects;\n\n if (\n packageJsonProjectGlobs?.length &&\n workspaceConfigProjectGlobs?.length &&\n !_.isEqual(packageJsonProjectGlobs, workspaceConfigProjectGlobs)\n ) {\n throw new WorkspaceError('PROJECT_GLOBS_MISMATCH', {\n data: {\n path: resolvedWorkspacePath,\n },\n });\n }\n\n let projectGlobs = packageJsonProjectGlobs ?? workspaceConfigProjectGlobs;\n\n // we're dealing with single-project workspace\n if (!projectGlobs) {\n let workspace = new this({\n path: resolvedWorkspacePath,\n isMultiProject: false,\n });\n\n await workspace.read();\n await workspace.readProjects();\n\n return workspace;\n }\n\n // we're dealing with multi-project workspace\n let workspace = new this({\n path: resolvedWorkspacePath,\n isMultiProject: true,\n projectGlobs,\n packageJson: rootPackageJson,\n });\n\n await workspace.read();\n await workspace.readProjects();\n\n return workspace;\n }\n\n /**\n * Traverses file system up from the search path and tries to find a directory that is a root of a workspace.\n *\n * @param searchPath Search path.\n * @returns Workspace path, if found.\n */\n static async find(searchPath: string): Promise<string | undefined> {\n let startingPath = await findExistingDirectory(path.resolve(searchPath));\n let currentPath = startingPath;\n let singlePackageWorkspacePath: string | undefined;\n let multiPackageWorkspacePath: string | undefined;\n\n while (!(\n isRootPath(currentPath) ||\n (singlePackageWorkspacePath && multiPackageWorkspacePath)\n )) {\n if (await containsWorkspace(currentPath)) {\n let packageJsonPath = path.join(currentPath, PACKAGE_JSON_FILENAME);\n let workspaceConfigPath = path.join(\n currentPath,\n CARSON_CONFIG_DIRECTORY,\n WORKSPACE_CONFIG_FILENAME,\n );\n\n if (await fs.pathExists(packageJsonPath)) {\n let packageJson = await readFile(packageJsonPath, jsonSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n\n if (!(packageJson instanceof Error)) {\n let projectGlobs = getPackageJsonWorkspaces(packageJson);\n\n if (projectGlobs?.length) {\n multiPackageWorkspacePath ??= currentPath;\n } else {\n singlePackageWorkspacePath ??= currentPath;\n }\n }\n }\n if (await fs.pathExists(workspaceConfigPath)) {\n let workspaceConfig = await readFile(workspaceConfigPath, workspaceConfigSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n\n if (!(workspaceConfig instanceof z.ZodError)) {\n let projectGlobs = workspaceConfig.projects;\n\n if (projectGlobs?.length) {\n multiPackageWorkspacePath ??= currentPath;\n } else {\n singlePackageWorkspacePath ??= currentPath;\n }\n }\n } else {\n singlePackageWorkspacePath ??= currentPath;\n }\n }\n\n currentPath = path.dirname(currentPath);\n }\n\n if (multiPackageWorkspacePath) {\n return multiPackageWorkspacePath;\n } else if (singlePackageWorkspacePath) {\n return singlePackageWorkspacePath;\n }\n\n return undefined;\n }\n\n /**\n * Traverses file system up from the search path and tries to find and read a workspace.\n */\n static async findAndRead<O extends WorkspaceFindAndReadOptions | undefined = undefined>(\n searchPath: string,\n options?: O,\n ): Promise<\n O extends undefined ? Workspace | Workspace<false> | undefined\n : NonNullable<O>['throwIfNotFound'] extends true ? Workspace | Workspace<false>\n : Workspace | Workspace<false> | undefined\n > {\n let workspacePath = await Workspace.find(searchPath);\n\n if (workspacePath) {\n return Workspace.read(workspacePath) as Promise<\n O extends undefined ? Workspace | Workspace<false> | undefined\n : NonNullable<O>['throwIfNotFound'] extends true ? Workspace | Workspace<false>\n : Workspace | Workspace<false> | undefined\n >;\n } else if (options?.throwIfNotFound) {\n throw new WorkspaceError('NO_WORKSPACE_FOUND', {\n messageParameters: [searchPath],\n data: {\n path: searchPath,\n },\n });\n }\n\n return undefined as unknown as Promise<\n O extends undefined ? Workspace | Workspace<false> | undefined\n : NonNullable<O>['throwIfNotFound'] extends true ? Workspace | Workspace<false>\n : Workspace | Workspace<false> | undefined\n >;\n }\n\n async read(): Promise<this> {\n if (!(await fs.pathExists(this.path))) {\n throw new WorkspaceError('NO_SUCH_WORKSPACE_PATH', {\n messageParameters: [this.path],\n data: {\n path: this.path,\n },\n });\n }\n\n let errors: Array<InstanceType<typeof WorkspaceError>> = [];\n let repositoryUrl = await getRepositoryUrl(this.path);\n let repositoryBranches = await getRepositoryBranches(this.path);\n\n // load workspace config\n let workspaceConfigPath = path.join(\n this.path,\n CARSON_CONFIG_DIRECTORY,\n WORKSPACE_CONFIG_FILENAME,\n );\n let doesWorkspaceConfigExist = await fs.pathExists(workspaceConfigPath);\n let workspaceConfig: WorkspaceConfig | z.ZodError;\n\n if (doesWorkspaceConfigExist) {\n workspaceConfig = await readFile(workspaceConfigPath, workspaceConfigSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n } else {\n workspaceConfig = {};\n }\n\n if (workspaceConfig instanceof z.ZodError) {\n let zodError = workspaceConfig;\n let workspaceError = new WorkspaceError('INVALID_WORKSPACE_CONFIG', {\n messageParameters: [workspaceConfigPath],\n data: {\n path: workspaceConfigPath,\n zodIssues: zodError.issues,\n },\n });\n\n errors.push(workspaceError);\n\n workspaceConfig = {};\n }\n\n if (this.isMultiProject) {\n // load root package.json\n let rootPackageJsonPath = path.join(this.path, 'package.json');\n let doesRootPackageJsonExist = await fs.pathExists(rootPackageJsonPath);\n let rootPackageJson: PackageJson | z.ZodError;\n\n if (doesRootPackageJsonExist) {\n rootPackageJson = await readFile(rootPackageJsonPath, packageJsonSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n } else {\n rootPackageJson = {};\n }\n\n if (rootPackageJson instanceof z.ZodError) {\n let zodError = rootPackageJson;\n let workspaceError = new WorkspaceError('INVALID_PACKAGE_JSON', {\n messageParameters: [rootPackageJsonPath],\n data: {\n path: rootPackageJsonPath,\n zodIssues: zodError.issues,\n },\n });\n\n errors.push(workspaceError);\n\n rootPackageJson = {};\n }\n\n // how to find projects\n let packageJsonProjectGlobs = getPackageJsonWorkspaces(rootPackageJson);\n let workspaceConfigProjectGlobs = workspaceConfig.projects;\n\n if (\n packageJsonProjectGlobs &&\n workspaceConfigProjectGlobs &&\n !_.isEqual(packageJsonProjectGlobs, workspaceConfigProjectGlobs)\n ) {\n throw new WorkspaceError('PROJECT_GLOBS_MISMATCH', {\n data: {\n path: this.path,\n },\n });\n }\n\n let projectGlobs = packageJsonProjectGlobs ?? workspaceConfigProjectGlobs;\n\n this.projectGlobs = (projectGlobs ?? []) as WorkspaceProjectGlobs<M>;\n this.packageJson = rootPackageJson as WorkspacePackageJson<M>;\n this.config = workspaceConfig;\n this.errors = errors;\n\n if (repositoryUrl) {\n this.repository = {\n url: repositoryUrl,\n branches: repositoryBranches ?? [],\n };\n } else if (repositoryBranches) {\n this.repository = {\n branches: repositoryBranches,\n };\n }\n\n await this.readProjects();\n\n return this;\n }\n\n // we're dealing with single-project workspace\n this.config = workspaceConfig;\n this.errors = errors;\n\n if (repositoryUrl) {\n this.repository = {\n url: repositoryUrl,\n branches: repositoryBranches ?? [],\n };\n } else if (repositoryBranches) {\n this.repository = {\n branches: repositoryBranches,\n };\n }\n\n await this.readProjects();\n\n return this;\n }\n\n async update({args}: WorkspaceUpdateOptions): Promise<this> {\n if (!this.config.template) {\n throw new WorkspaceError('MISSING_CARSON_TEMPLATE_ID', {\n messageParameters: [\n path.join(this.path, CARSON_CONFIG_DIRECTORY, WORKSPACE_CONFIG_FILENAME),\n ],\n });\n }\n\n let template = await readCarsonTemplate(this.config.template);\n let templateRenders = await renderCarsonTemplate({\n template,\n templateData: {\n workspace: this,\n args,\n },\n });\n\n await applyTemplateRenders({\n templateRenders,\n targetPath: this.path,\n snapshotPath:\n template.config.autoEject ?\n undefined\n : path.join(this.path, CARSON_CONFIG_DIRECTORY, WORKSPACE_SNAPSHOT_FILENAME),\n ignoreStrategies: ['create'],\n });\n\n await this.read();\n\n return this;\n }\n\n getProject(projectName: Project<M> | string): Project<M> | undefined {\n for (let project of this.projects) {\n if (project.name === projectName || project === projectName) {\n return project;\n }\n }\n\n return undefined;\n }\n\n async createProject({\n templateId,\n projectPath,\n projectName,\n args,\n }: WorkspaceCreateProjectOptions): Promise<Project<M>> {\n let resolvedProjectPath = path.resolve(projectPath);\n\n if (this.projects.some((project) => resolvedProjectPath === project.path)) {\n throw new WorkspaceError('DUPLICATE_PROJECT_PATH', {\n messageParameters: [resolvedProjectPath],\n });\n }\n\n if (this.projects.some((project) => projectName === project.name)) {\n throw new WorkspaceError('DUPLICATE_PROJECT_NAME', {messageParameters: [projectName]});\n }\n\n if (!this.isMultiProject && this.projects.length >= 1) {\n throw new WorkspaceError('TOO_MANY_PROJECTS');\n }\n\n if (!this.isMultiProject && projectPath !== this.path) {\n throw new WorkspaceError('PATH_MISMATCH');\n }\n\n let newProject = await Project.create({\n templateId,\n projectPath,\n projectName,\n args,\n workspace: this,\n });\n\n this.addProject(newProject);\n\n return newProject;\n }\n\n addProject(newProject: Project<M>): this {\n if (this.projects.some((project) => newProject.path === project.path)) {\n throw new WorkspaceError('DUPLICATE_PROJECT_PATH', {\n messageParameters: [newProject.path],\n });\n }\n\n if (this.projects.some((project) => newProject.name === project.name)) {\n throw new WorkspaceError('DUPLICATE_PROJECT_NAME', {messageParameters: [newProject.name]});\n }\n\n if (!this.isMultiProject && this.projects.length >= 1) {\n throw new WorkspaceError('TOO_MANY_PROJECTS');\n }\n\n if (!this.isMultiProject && newProject.path !== this.path) {\n throw new WorkspaceError('PATH_MISMATCH');\n }\n\n this.projects.push(newProject);\n this.sortProjects();\n this.updateDependencies();\n\n return this;\n }\n\n addProjects(newProjects: Array<Project<M>>): this {\n for (let newProject of newProjects) {\n if (this.projects.some((project) => newProject.path === project.path)) {\n throw new WorkspaceError('DUPLICATE_PROJECT_PATH', {\n messageParameters: [newProject.path],\n });\n }\n\n if (this.projects.some((project) => newProject.name === project.name)) {\n throw new WorkspaceError('DUPLICATE_PROJECT_NAME', {messageParameters: [newProject.name]});\n }\n\n if (!this.isMultiProject && this.projects.length >= 1) {\n throw new WorkspaceError('TOO_MANY_PROJECTS');\n }\n\n if (!this.isMultiProject && newProject.path !== this.path) {\n throw new WorkspaceError('PATH_MISMATCH');\n }\n\n this.projects.push(newProject);\n }\n\n this.sortProjects();\n this.updateDependencies();\n\n return this;\n }\n\n async readProjects(): Promise<Array<Project<M>>> {\n if (this.projectGlobs) {\n let projects: Array<Project<M>> = [];\n let packagePaths = await glob(this.projectGlobs, {\n cwd: this.path,\n onlyDirectories: true,\n });\n\n for (let packagePath of packagePaths) {\n let projectPath = path.join(this.path, packagePath);\n\n if (await containsProject(projectPath)) {\n let project = await Project.read(projectPath, this);\n\n projects.push(project);\n }\n }\n\n this.projects = projects;\n\n this.sortProjects();\n this.updateDependencies();\n } else if (await containsProject(this.path)) {\n this.projects = [await Project.read(this.path, this)];\n\n this.sortProjects();\n this.updateDependencies();\n }\n\n return this.projects;\n }\n\n protected sortProjects(): void {\n this.projects.sort(compareProjectPath);\n }\n\n protected updateDependencies(): void {\n this.dependencies = WorkspaceDependencies.fromWorkspace(this);\n this.devDependencies = WorkspaceDependencies.fromWorkspace(this, {\n includeOnlyDevDependencies: true,\n });\n this.allDependencies = WorkspaceDependencies.fromWorkspace(this, {\n includeDevDependencies: true,\n includeWorkspaceDependencies: true,\n });\n this.dependencyVersions = this.allDependencies.getVersions({\n useExactVersions: true,\n });\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAQ,sBAAsB,uBAAuB,kBAAiB;AACtE,SAAQ,YAA8B,mBAAmB,gBAAe;AACxE,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,OAAO,WAAW;AAClB,OAAO,OAAO;AACd,OAAO,UAAU;AACjB,SAAQ,SAAQ;AAEhB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AACP,SAAQ,4BAA2B;AACnC,SAAQ,0BAAyB;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AAAA,EACd;AAAA,EAEU,eAAqB;AAC7B,SAAK,SAAS,KAAK,kBAAkB;AAAA,EACvC;AAAA,EAEU,qBAA2B;AACnC,SAAK,eAAe,sBAAsB,cAAc,IAAI;AAC5D,SAAK,kBAAkB,sBAAsB,cAAc,MAAM;AAAA,MAC/D,4BAA4B;AAAA,IAC9B,CAAC;AACD,SAAK,kBAAkB,sBAAsB,cAAc,MAAM;AAAA,MAC/D,wBAAwB;AAAA,MACxB,8BAA8B;AAAA,IAChC,CAAC;AACD,SAAK,qBAAqB,KAAK,gBAAgB,YAAY;AAAA,MACzD,kBAAkB;AAAA,IACpB,CAAC;AAAA,EACH;AACF;",
|
|
4
|
+
"sourcesContent": ["import {ensureEmptyDirectory, findExistingDirectory, isRootPath} from '@jakubmazanec/fs-utils';\nimport {jsonSchema, type PackageJson, packageJsonSchema, readFile} from '@jakubmazanec/zod-utils';\nimport glob from 'fast-glob';\nimport fs from 'fs-extra';\nimport json5 from 'json5';\nimport _ from 'lodash';\nimport path from 'node:path';\nimport {z} from 'zod';\n\nimport {\n CARSON_CONFIG_DIRECTORY,\n PACKAGE_JSON_FILENAME,\n WORKSPACE_CONFIG_FILENAME,\n WORKSPACE_SNAPSHOT_FILENAME,\n} from '../constants.js';\nimport {applyTemplateRenders} from '../template/applyTemplateRenders.js';\nimport {readCarsonTemplate} from '../template/internals.js';\nimport {renderCarsonTemplate} from '../template/renderCarsonTemplate.js';\nimport {\n compareProjectPath,\n containsProject,\n containsWorkspace,\n getPackageJsonWorkspaces,\n getRepositoryBranches,\n getRepositoryUrl,\n} from './internals.js';\nimport {Project} from './Project.js';\nimport {saveWorkspaceConfig} from './saveWorkspaceConfig.js';\nimport {workspaceConfigSchema} from './WorkspaceConfig.js';\nimport {type WorkspaceConfig} from './WorkspaceConfig.js';\nimport {type WorkspaceCreateOptions} from './WorkspaceCreateOptions.js';\nimport {type WorkspaceCreateProjectOptions} from './WorkspaceCreateProjectOptions.js';\nimport {WorkspaceDependencies} from './WorkspaceDependencies.js';\nimport {WorkspaceError} from './WorkspaceError.js';\nimport {type WorkspaceFindAndReadOptions} from './WorkspaceFindAndReadOptions.js';\nimport {type WorkspaceOptions} from './WorkspaceOptions.js';\nimport {type WorkspacePackageJson} from './WorkspacePackageJson.js';\nimport {type WorkspaceProjectGlobs} from './WorkspaceProjectGlobs.js';\nimport {type WorkspaceProjects} from './WorkspaceProjects.js';\nimport {type WorkspaceRepository} from './WorkspaceRepository.js';\nimport {type WorkspaceUpdateOptions} from './WorkspaceUpdateOptions.js';\n\n/**\n * Workspace represent a directory, usually a git repository, that contains {@link Project}\n * instances.\n *\n * @typeParam M If true, the workspace is multi-project workspace (so-called \"monorepo\").\n */\nexport class Workspace<M extends boolean = true> {\n /** Workspace path. */\n readonly path: string;\n\n /** Does the workspace contain a multiple projects? */\n readonly isMultiProject: M;\n\n /** Globs used to find projects. */\n projectGlobs: WorkspaceProjectGlobs<M>;\n\n /** Workspace projects. */\n projects: WorkspaceProjects<M>;\n\n /** Workspace configuration; if it's not found, the default is an empty object. */\n config: WorkspaceConfig;\n\n /**\n * Parsed workspace `package.json` file (if the workspace contains multiple projects); if it's\n * not found, the default is an empty object.\n */\n packageJson: WorkspacePackageJson<M>;\n\n /** Workspace git repository. */\n repository?: WorkspaceRepository;\n\n /** Dependencies of all projects. */\n dependencies: WorkspaceDependencies<M> = [] as unknown as WorkspaceDependencies<M>;\n\n /** Development dependencies of all projects. */\n devDependencies: WorkspaceDependencies<M> = [] as unknown as WorkspaceDependencies<M>;\n\n /** All dependencies of all projects and workspace dependencies. */\n allDependencies: WorkspaceDependencies<M> = [] as unknown as WorkspaceDependencies<M>;\n\n /** Versions of each dependency. */\n dependencyVersions: Record<string, string[]> = {};\n\n /** Errors found during reading from the file system. */\n errors: Array<InstanceType<typeof WorkspaceError>> = [];\n\n constructor(options: WorkspaceOptions<M>) {\n this.path = options.path;\n\n if (options.isMultiProject === undefined || options.isMultiProject) {\n this.isMultiProject = true as M;\n\n let projectGlobOption = (options as WorkspaceOptions<true>).projectGlobs;\n\n if (projectGlobOption) {\n this.projectGlobs = projectGlobOption as WorkspaceProjectGlobs<M>;\n } else {\n this.projectGlobs = [] as string[] as WorkspaceProjectGlobs<M>;\n }\n\n this.projects = [] as Array<Project<M>>;\n\n let {projects} = options as WorkspaceOptions<true>;\n\n if (projects) {\n this.addProjects(projects.map((project) => new Project({...project, workspace: this})));\n }\n\n let packageJsonOption = (options as WorkspaceOptions<true>).packageJson;\n\n if (packageJsonOption) {\n this.packageJson = packageJsonOption as M extends true ? PackageJson : null;\n } else {\n let emptyPackageJson: PackageJson = {};\n\n this.packageJson = emptyPackageJson as M extends true ? PackageJson : null;\n }\n } else {\n this.isMultiProject = false as M;\n this.projectGlobs = null as M extends true ? string[] : null;\n this.packageJson = null as M extends true ? PackageJson : null;\n this.projects = [] as Array<Project<M>>;\n\n let {projects} = options as WorkspaceOptions<false>;\n\n if (projects) {\n this.addProjects(projects.map((project) => new Project({...project, workspace: this})));\n }\n }\n\n let configOption = options.config;\n\n if (configOption) {\n this.config = configOption;\n } else {\n let emptyWorkspaceConfig: WorkspaceConfig = {};\n\n this.config = emptyWorkspaceConfig;\n }\n\n if (options.repository) {\n this.repository = options.repository;\n }\n\n if (options.errors) {\n this.errors = options.errors;\n }\n\n // add missing project globs\n if (this.isMultiProject && !(this.projectGlobs as string[]).length) {\n let packageJsonWorkspaces = getPackageJsonWorkspaces(this.packageJson);\n\n if (packageJsonWorkspaces) {\n this.projectGlobs = [...packageJsonWorkspaces] as M extends true ? string[] : null;\n }\n }\n\n this.sortProjects();\n this.updateDependencies();\n }\n\n /**\n * Creates new workspace within the file system.\n *\n * @param options Options.\n * @returns The new workspace.\n */\n static async create({args, path: workspacePath, templateId}: WorkspaceCreateOptions) {\n // TODO: test that workspace returned by this method has the same value of isMultiProject when\n // the same workspace is after its creation re-read with .read()\n let workspace = new this({\n path: workspacePath,\n config: {\n template: templateId,\n },\n });\n\n try {\n await ensureEmptyDirectory(workspace.path, {allowGit: true});\n } catch {\n throw new WorkspaceError('WORKSPACE_PATH_NOT_EMPTY', {\n messageParameters: [workspace.path],\n data: {\n path: workspace.path,\n },\n });\n }\n\n let template = await readCarsonTemplate(templateId);\n let templateRenders = await renderCarsonTemplate({\n template,\n templateData: {\n workspace,\n args,\n },\n });\n\n if (!template.config.autoEject) {\n await saveWorkspaceConfig({\n workspacePath: workspace.path,\n workspaceConfig: {template: templateId},\n });\n }\n\n await applyTemplateRenders({\n templateRenders,\n targetPath: workspace.path,\n snapshotPath:\n template.config.autoEject ?\n undefined\n : path.join(workspace.path, CARSON_CONFIG_DIRECTORY, WORKSPACE_SNAPSHOT_FILENAME),\n ignoreStrategies: ['check'],\n });\n\n return Workspace.read(workspace.path);\n }\n\n static async read(workspacePath: string): Promise<Workspace | Workspace<false>> {\n let resolvedWorkspacePath = path.resolve(workspacePath);\n\n if (!(await fs.pathExists(resolvedWorkspacePath))) {\n throw new WorkspaceError('NO_SUCH_WORKSPACE_PATH', {\n messageParameters: [resolvedWorkspacePath],\n data: {\n path: resolvedWorkspacePath,\n },\n });\n }\n\n // load root package.json\n let rootPackageJsonPath = path.join(resolvedWorkspacePath, 'package.json');\n let doesRootPackageJsonExist = await fs.pathExists(rootPackageJsonPath);\n let rootPackageJson: PackageJson | z.ZodError;\n\n if (doesRootPackageJsonExist) {\n rootPackageJson = await readFile(rootPackageJsonPath, packageJsonSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n } else {\n rootPackageJson = {};\n }\n\n if (rootPackageJson instanceof z.ZodError) {\n rootPackageJson = {};\n\n // even if the package.json file has errors, maybe there's still a correct workspace field\n try {\n let rootJson = await readFile(rootPackageJsonPath, jsonSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n throwOnZodError: true,\n });\n let projectGlobs = getPackageJsonWorkspaces(rootJson);\n\n // add back to the empty package.json object\n if (projectGlobs) {\n rootPackageJson.workspaces = projectGlobs;\n }\n } catch {\n // no-op\n }\n }\n\n // load workspace config\n let workspaceConfigPath = path.join(\n resolvedWorkspacePath,\n CARSON_CONFIG_DIRECTORY,\n WORKSPACE_CONFIG_FILENAME,\n );\n let doesWorkspaceConfigExist = await fs.pathExists(workspaceConfigPath);\n let workspaceConfig: WorkspaceConfig | z.ZodError;\n\n if (doesWorkspaceConfigExist) {\n workspaceConfig = await readFile(workspaceConfigPath, workspaceConfigSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n } else {\n workspaceConfig = {};\n }\n\n if (workspaceConfig instanceof z.ZodError) {\n workspaceConfig = {};\n }\n\n // how to find projects\n let packageJsonProjectGlobs = getPackageJsonWorkspaces(rootPackageJson);\n let workspaceConfigProjectGlobs = workspaceConfig.projects;\n\n if (\n packageJsonProjectGlobs?.length &&\n workspaceConfigProjectGlobs?.length &&\n !_.isEqual(packageJsonProjectGlobs, workspaceConfigProjectGlobs)\n ) {\n throw new WorkspaceError('PROJECT_GLOBS_MISMATCH', {\n data: {\n path: resolvedWorkspacePath,\n },\n });\n }\n\n let projectGlobs = packageJsonProjectGlobs ?? workspaceConfigProjectGlobs;\n\n // we're dealing with single-project workspace\n if (!projectGlobs) {\n let workspace = new this({\n path: resolvedWorkspacePath,\n isMultiProject: false,\n });\n\n await workspace.read();\n await workspace.readProjects();\n\n return workspace;\n }\n\n // we're dealing with multi-project workspace\n let workspace = new this({\n path: resolvedWorkspacePath,\n isMultiProject: true,\n projectGlobs,\n packageJson: rootPackageJson,\n });\n\n await workspace.read();\n await workspace.readProjects();\n\n return workspace;\n }\n\n /**\n * Traverses file system up from the search path and tries to find a directory that is a root of\n * a workspace.\n *\n * @param searchPath Search path.\n * @returns Workspace path, if found.\n */\n static async find(searchPath: string): Promise<string | undefined> {\n let startingPath = await findExistingDirectory(path.resolve(searchPath));\n let currentPath = startingPath;\n let singlePackageWorkspacePath: string | undefined;\n let multiPackageWorkspacePath: string | undefined;\n\n while (!(\n isRootPath(currentPath) ||\n (singlePackageWorkspacePath && multiPackageWorkspacePath)\n )) {\n if (await containsWorkspace(currentPath)) {\n let packageJsonPath = path.join(currentPath, PACKAGE_JSON_FILENAME);\n let workspaceConfigPath = path.join(\n currentPath,\n CARSON_CONFIG_DIRECTORY,\n WORKSPACE_CONFIG_FILENAME,\n );\n\n if (await fs.pathExists(packageJsonPath)) {\n let packageJson = await readFile(packageJsonPath, jsonSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n\n if (!(packageJson instanceof Error)) {\n let projectGlobs = getPackageJsonWorkspaces(packageJson);\n\n if (projectGlobs?.length) {\n multiPackageWorkspacePath ??= currentPath;\n } else {\n singlePackageWorkspacePath ??= currentPath;\n }\n }\n }\n if (await fs.pathExists(workspaceConfigPath)) {\n let workspaceConfig = await readFile(workspaceConfigPath, workspaceConfigSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n\n if (!(workspaceConfig instanceof z.ZodError)) {\n let projectGlobs = workspaceConfig.projects;\n\n if (projectGlobs?.length) {\n multiPackageWorkspacePath ??= currentPath;\n } else {\n singlePackageWorkspacePath ??= currentPath;\n }\n }\n } else {\n singlePackageWorkspacePath ??= currentPath;\n }\n }\n\n currentPath = path.dirname(currentPath);\n }\n\n if (multiPackageWorkspacePath) {\n return multiPackageWorkspacePath;\n } else if (singlePackageWorkspacePath) {\n return singlePackageWorkspacePath;\n }\n\n return undefined;\n }\n\n /**\n * Traverses file system up from the search path and tries to find and read a workspace.\n */\n static async findAndRead<O extends WorkspaceFindAndReadOptions | undefined = undefined>(\n searchPath: string,\n options?: O,\n ): Promise<\n O extends undefined ? Workspace | Workspace<false> | undefined\n : NonNullable<O>['throwIfNotFound'] extends true ? Workspace | Workspace<false>\n : Workspace | Workspace<false> | undefined\n > {\n let workspacePath = await Workspace.find(searchPath);\n\n if (workspacePath) {\n return Workspace.read(workspacePath) as Promise<\n O extends undefined ? Workspace | Workspace<false> | undefined\n : NonNullable<O>['throwIfNotFound'] extends true ? Workspace | Workspace<false>\n : Workspace | Workspace<false> | undefined\n >;\n } else if (options?.throwIfNotFound) {\n throw new WorkspaceError('NO_WORKSPACE_FOUND', {\n messageParameters: [searchPath],\n data: {\n path: searchPath,\n },\n });\n }\n\n return undefined as unknown as Promise<\n O extends undefined ? Workspace | Workspace<false> | undefined\n : NonNullable<O>['throwIfNotFound'] extends true ? Workspace | Workspace<false>\n : Workspace | Workspace<false> | undefined\n >;\n }\n\n async read(): Promise<this> {\n if (!(await fs.pathExists(this.path))) {\n throw new WorkspaceError('NO_SUCH_WORKSPACE_PATH', {\n messageParameters: [this.path],\n data: {\n path: this.path,\n },\n });\n }\n\n let errors: Array<InstanceType<typeof WorkspaceError>> = [];\n let repositoryUrl = await getRepositoryUrl(this.path);\n let repositoryBranches = await getRepositoryBranches(this.path);\n\n // load workspace config\n let workspaceConfigPath = path.join(\n this.path,\n CARSON_CONFIG_DIRECTORY,\n WORKSPACE_CONFIG_FILENAME,\n );\n let doesWorkspaceConfigExist = await fs.pathExists(workspaceConfigPath);\n let workspaceConfig: WorkspaceConfig | z.ZodError;\n\n if (doesWorkspaceConfigExist) {\n workspaceConfig = await readFile(workspaceConfigPath, workspaceConfigSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n } else {\n workspaceConfig = {};\n }\n\n if (workspaceConfig instanceof z.ZodError) {\n let zodError = workspaceConfig;\n let workspaceError = new WorkspaceError('INVALID_WORKSPACE_CONFIG', {\n messageParameters: [workspaceConfigPath],\n data: {\n path: workspaceConfigPath,\n zodIssues: zodError.issues,\n },\n });\n\n errors.push(workspaceError);\n\n workspaceConfig = {};\n }\n\n if (this.isMultiProject) {\n // load root package.json\n let rootPackageJsonPath = path.join(this.path, 'package.json');\n let doesRootPackageJsonExist = await fs.pathExists(rootPackageJsonPath);\n let rootPackageJson: PackageJson | z.ZodError;\n\n if (doesRootPackageJsonExist) {\n rootPackageJson = await readFile(rootPackageJsonPath, packageJsonSchema, {\n parser: (rawString: string) => json5.parse<unknown>(rawString),\n });\n } else {\n rootPackageJson = {};\n }\n\n if (rootPackageJson instanceof z.ZodError) {\n let zodError = rootPackageJson;\n let workspaceError = new WorkspaceError('INVALID_PACKAGE_JSON', {\n messageParameters: [rootPackageJsonPath],\n data: {\n path: rootPackageJsonPath,\n zodIssues: zodError.issues,\n },\n });\n\n errors.push(workspaceError);\n\n rootPackageJson = {};\n }\n\n // how to find projects\n let packageJsonProjectGlobs = getPackageJsonWorkspaces(rootPackageJson);\n let workspaceConfigProjectGlobs = workspaceConfig.projects;\n\n if (\n packageJsonProjectGlobs &&\n workspaceConfigProjectGlobs &&\n !_.isEqual(packageJsonProjectGlobs, workspaceConfigProjectGlobs)\n ) {\n throw new WorkspaceError('PROJECT_GLOBS_MISMATCH', {\n data: {\n path: this.path,\n },\n });\n }\n\n let projectGlobs = packageJsonProjectGlobs ?? workspaceConfigProjectGlobs;\n\n this.projectGlobs = (projectGlobs ?? []) as WorkspaceProjectGlobs<M>;\n this.packageJson = rootPackageJson as WorkspacePackageJson<M>;\n this.config = workspaceConfig;\n this.errors = errors;\n\n if (repositoryUrl) {\n this.repository = {\n url: repositoryUrl,\n branches: repositoryBranches ?? [],\n };\n } else if (repositoryBranches) {\n this.repository = {\n branches: repositoryBranches,\n };\n }\n\n await this.readProjects();\n\n return this;\n }\n\n // we're dealing with single-project workspace\n this.config = workspaceConfig;\n this.errors = errors;\n\n if (repositoryUrl) {\n this.repository = {\n url: repositoryUrl,\n branches: repositoryBranches ?? [],\n };\n } else if (repositoryBranches) {\n this.repository = {\n branches: repositoryBranches,\n };\n }\n\n await this.readProjects();\n\n return this;\n }\n\n async update({args}: WorkspaceUpdateOptions): Promise<this> {\n if (!this.config.template) {\n throw new WorkspaceError('MISSING_CARSON_TEMPLATE_ID', {\n messageParameters: [\n path.join(this.path, CARSON_CONFIG_DIRECTORY, WORKSPACE_CONFIG_FILENAME),\n ],\n });\n }\n\n let template = await readCarsonTemplate(this.config.template);\n let templateRenders = await renderCarsonTemplate({\n template,\n templateData: {\n workspace: this,\n args,\n },\n });\n\n await applyTemplateRenders({\n templateRenders,\n targetPath: this.path,\n snapshotPath:\n template.config.autoEject ?\n undefined\n : path.join(this.path, CARSON_CONFIG_DIRECTORY, WORKSPACE_SNAPSHOT_FILENAME),\n ignoreStrategies: ['create'],\n });\n\n await this.read();\n\n return this;\n }\n\n getProject(projectName: Project<M> | string): Project<M> | undefined {\n for (let project of this.projects) {\n if (project.name === projectName || project === projectName) {\n return project;\n }\n }\n\n return undefined;\n }\n\n async createProject({\n templateId,\n projectPath,\n projectName,\n args,\n }: WorkspaceCreateProjectOptions): Promise<Project<M>> {\n let resolvedProjectPath = path.resolve(projectPath);\n\n if (this.projects.some((project) => resolvedProjectPath === project.path)) {\n throw new WorkspaceError('DUPLICATE_PROJECT_PATH', {\n messageParameters: [resolvedProjectPath],\n });\n }\n\n if (this.projects.some((project) => projectName === project.name)) {\n throw new WorkspaceError('DUPLICATE_PROJECT_NAME', {messageParameters: [projectName]});\n }\n\n if (!this.isMultiProject && this.projects.length >= 1) {\n throw new WorkspaceError('TOO_MANY_PROJECTS');\n }\n\n if (!this.isMultiProject && projectPath !== this.path) {\n throw new WorkspaceError('PATH_MISMATCH');\n }\n\n let newProject = await Project.create({\n templateId,\n projectPath,\n projectName,\n args,\n workspace: this,\n });\n\n this.addProject(newProject);\n\n return newProject;\n }\n\n addProject(newProject: Project<M>): this {\n if (this.projects.some((project) => newProject.path === project.path)) {\n throw new WorkspaceError('DUPLICATE_PROJECT_PATH', {\n messageParameters: [newProject.path],\n });\n }\n\n if (this.projects.some((project) => newProject.name === project.name)) {\n throw new WorkspaceError('DUPLICATE_PROJECT_NAME', {messageParameters: [newProject.name]});\n }\n\n if (!this.isMultiProject && this.projects.length >= 1) {\n throw new WorkspaceError('TOO_MANY_PROJECTS');\n }\n\n if (!this.isMultiProject && newProject.path !== this.path) {\n throw new WorkspaceError('PATH_MISMATCH');\n }\n\n this.projects.push(newProject);\n this.sortProjects();\n this.updateDependencies();\n\n return this;\n }\n\n addProjects(newProjects: Array<Project<M>>): this {\n for (let newProject of newProjects) {\n if (this.projects.some((project) => newProject.path === project.path)) {\n throw new WorkspaceError('DUPLICATE_PROJECT_PATH', {\n messageParameters: [newProject.path],\n });\n }\n\n if (this.projects.some((project) => newProject.name === project.name)) {\n throw new WorkspaceError('DUPLICATE_PROJECT_NAME', {messageParameters: [newProject.name]});\n }\n\n if (!this.isMultiProject && this.projects.length >= 1) {\n throw new WorkspaceError('TOO_MANY_PROJECTS');\n }\n\n if (!this.isMultiProject && newProject.path !== this.path) {\n throw new WorkspaceError('PATH_MISMATCH');\n }\n\n this.projects.push(newProject);\n }\n\n this.sortProjects();\n this.updateDependencies();\n\n return this;\n }\n\n async readProjects(): Promise<Array<Project<M>>> {\n if (this.projectGlobs) {\n let projects: Array<Project<M>> = [];\n let packagePaths = await glob(this.projectGlobs, {\n cwd: this.path,\n onlyDirectories: true,\n });\n\n for (let packagePath of packagePaths) {\n let projectPath = path.join(this.path, packagePath);\n\n if (await containsProject(projectPath)) {\n let project = await Project.read(projectPath, this);\n\n projects.push(project);\n }\n }\n\n this.projects = projects;\n\n this.sortProjects();\n this.updateDependencies();\n } else if (await containsProject(this.path)) {\n this.projects = [await Project.read(this.path, this)];\n\n this.sortProjects();\n this.updateDependencies();\n }\n\n return this.projects;\n }\n\n protected sortProjects(): void {\n this.projects.sort(compareProjectPath);\n }\n\n protected updateDependencies(): void {\n this.dependencies = WorkspaceDependencies.fromWorkspace(this);\n this.devDependencies = WorkspaceDependencies.fromWorkspace(this, {\n includeOnlyDevDependencies: true,\n });\n this.allDependencies = WorkspaceDependencies.fromWorkspace(this, {\n includeDevDependencies: true,\n includeWorkspaceDependencies: true,\n });\n this.dependencyVersions = this.allDependencies.getVersions({\n useExactVersions: true,\n });\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAQ,sBAAsB,uBAAuB,kBAAiB;AACtE,SAAQ,YAA8B,mBAAmB,gBAAe;AACxE,OAAO,UAAU;AACjB,OAAO,QAAQ;AACf,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mB;AAAA,IAC1B,WAAW,MAAM,gBAAgB,KAAK,IAAI,GAAG;AAC3C,WAAK,WAAW,CAAC,MAAM,QAAQ,KAAK,KAAK,MAAM,IAAI,CAAC;AAEpD,WAAK,aAAa;AAClB,WAAK,mBAAmB;AAAA,IAC1B;AAEA,WAAO,KAAK;AAAA,EACd;AAAA,EAEU,eAAqB;AAC7B,SAAK,SAAS,KAAK,kBAAkB;AAAA,EACvC;AAAA,EAEU,qBAA2B;AACnC,SAAK,eAAe,sBAAsB,cAAc,IAAI;AAC5D,SAAK,kBAAkB,sBAAsB,cAAc,MAAM;AAAA,MAC/D,4BAA4B;AAAA,IAC9B,CAAC;AACD,SAAK,kBAAkB,sBAAsB,cAAc,MAAM;AAAA,MAC/D,wBAAwB;AAAA,MACxB,8BAA8B;AAAA,IAChC,CAAC;AACD,SAAK,qBAAqB,KAAK,gBAAgB,YAAY;AAAA,MACzD,kBAAkB;AAAA,IACpB,CAAC;AAAA,EACH;AACF;",
|
|
6
6
|
"names": ["projectGlobs", "workspace"]
|
|
7
7
|
}
|
|
@@ -3,7 +3,8 @@ import { type WorkspaceDependenciesFromWorkspaceOptions } from './WorkspaceDepen
|
|
|
3
3
|
import { type WorkspaceDependenciesGetVersionsOptions } from './WorkspaceDependenciesGetVersionsOptions.js';
|
|
4
4
|
import { type WorkspaceDependency } from './WorkspaceDependency.js';
|
|
5
5
|
/**
|
|
6
|
-
* A collection of {@link WorkspaceDependency | workspace dependencies} that are installed in
|
|
6
|
+
* A collection of {@link WorkspaceDependency | workspace dependencies} that are installed in
|
|
7
|
+
* {@link Workspace | a workspace}.
|
|
7
8
|
*/
|
|
8
9
|
export declare class WorkspaceDependencies<M extends boolean = true> extends Array<WorkspaceDependency> {
|
|
9
10
|
/** The workspace the dependencies are installed in. */
|
|
@@ -17,7 +18,8 @@ export declare class WorkspaceDependencies<M extends boolean = true> extends Arr
|
|
|
17
18
|
*/
|
|
18
19
|
push(...newWorkspaceDependencies: WorkspaceDependency[]): number;
|
|
19
20
|
/**
|
|
20
|
-
* Creates new {@link WorkspaceDependencies} instance from a {@link Workspace} instance and its
|
|
21
|
+
* Creates new {@link WorkspaceDependencies} instance from a {@link Workspace} instance and its
|
|
22
|
+
* dependencies.
|
|
21
23
|
*
|
|
22
24
|
* @param workspace The workspace from which the dependnecies are taken.
|
|
23
25
|
* @param options Options.
|
|
@@ -52,7 +52,8 @@ export class WorkspaceDependencies extends Array {
|
|
|
52
52
|
return this.length;
|
|
53
53
|
}
|
|
54
54
|
/**
|
|
55
|
-
* Creates new {@link WorkspaceDependencies} instance from a {@link Workspace} instance and its
|
|
55
|
+
* Creates new {@link WorkspaceDependencies} instance from a {@link Workspace} instance and its
|
|
56
|
+
* dependencies.
|
|
56
57
|
*
|
|
57
58
|
* @param workspace The workspace from which the dependnecies are taken.
|
|
58
59
|
* @param options Options.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../source/workspace/WorkspaceDependencies.ts"],
|
|
4
|
-
"sourcesContent": ["import _ from 'lodash';\nimport semver from 'semver';\n\nimport {compareSemver, compareWorkspaceDependencyProjectName} from './internals.js';\nimport {type Workspace} from './Workspace.js';\nimport {type WorkspaceDependenciesFromWorkspaceOptions} from './WorkspaceDependenciesFromWorkspaceOptions.js';\nimport {type WorkspaceDependenciesGetVersionsOptions} from './WorkspaceDependenciesGetVersionsOptions.js';\nimport {type WorkspaceDependency} from './WorkspaceDependency.js';\n\n/**\n * A collection of {@link WorkspaceDependency | workspace dependencies} that are installed in {@link Workspace | a workspace}.\n */\nexport class WorkspaceDependencies<M extends boolean = true> extends Array<WorkspaceDependency> {\n /** The workspace the dependencies are installed in. */\n workspace: Workspace<M>;\n\n constructor(...args: [...WorkspaceDependency[], Workspace<M>]) {\n super();\n\n if (args.length === 1) {\n [this.workspace] = args as [Workspace<M>];\n } else {\n let values = args.slice(0, -1) as WorkspaceDependency[];\n let workspace = args.at(-1) as Workspace<M>;\n\n this.push(...values);\n\n this.workspace = workspace;\n }\n }\n\n /**\n * Adds one or more new dependencies.\n *\n * @param newWorkspaceDependencies The dependencies to add.\n * @returns The new length of the collection.\n */\n override push(...newWorkspaceDependencies: WorkspaceDependency[]): number {\n for (let newWorkspaceDependency of newWorkspaceDependencies) {\n let doesExist = false;\n\n for (let workspaceDependency of this) {\n if (workspaceDependency.name === newWorkspaceDependency.name) {\n doesExist = true;\n\n workspaceDependency.versions = _.union(\n workspaceDependency.versions,\n newWorkspaceDependency.versions,\n );\n workspaceDependency.exactVersions = _.union(\n workspaceDependency.exactVersions,\n newWorkspaceDependency.exactVersions,\n );\n workspaceDependency.projects = _.unionWith(\n workspaceDependency.projects,\n newWorkspaceDependency.projects,\n (a, b) => a.name === b.name,\n );\n\n workspaceDependency.versions.sort(compareSemver);\n workspaceDependency.exactVersions.sort(compareSemver);\n workspaceDependency.projects.sort(compareWorkspaceDependencyProjectName);\n }\n }\n\n if (!doesExist) {\n super.push(newWorkspaceDependency);\n }\n }\n\n return this.length;\n }\n\n /**\n * Creates new {@link WorkspaceDependencies} instance from a {@link Workspace} instance and its dependencies.\n *\n * @param workspace The workspace from which the dependnecies are taken.\n * @param options Options.\n * @returns The new {@link WorkspaceDependencies} instance.\n */\n static fromWorkspace<M extends boolean = true>(\n workspace: Workspace<M>,\n options?: WorkspaceDependenciesFromWorkspaceOptions,\n ) {\n let workspaceDependencies: WorkspaceDependency[] = [];\n\n if (options?.includeWorkspaceDependencies) {\n for (let [dependencyName, dependencyVersion] of Object.entries({\n ...workspace.packageJson?.dependencies,\n ...workspace.packageJson?.devDependencies,\n ...(workspace.packageJson?.engines as Record<string, string>),\n })) {\n let exactDependencyVersion =\n semver.validRange(dependencyVersion) ?\n (semver.minVersion(dependencyVersion)?.format() ??\n semver.coerce(dependencyVersion)?.format() ??\n dependencyVersion.trim())\n : dependencyVersion.trim();\n\n let workspaceDependency: WorkspaceDependency = {\n name: dependencyName,\n versions: [dependencyVersion],\n exactVersions: [exactDependencyVersion],\n projects: [],\n };\n\n workspaceDependencies.push(workspaceDependency);\n }\n }\n\n for (let project of workspace.projects) {\n if (!options?.includeOnlyDevDependencies) {\n for (let [dependencyName, dependencyVersion] of Object.entries({\n ...project.packageJson.dependencies,\n ...(workspace.packageJson?.engines as Record<string, string>),\n })) {\n let exactDependencyVersion =\n semver.validRange(dependencyVersion) ?\n (semver.minVersion(dependencyVersion)?.format() ??\n semver.coerce(dependencyVersion)?.format() ??\n dependencyVersion.trim())\n : dependencyVersion.trim();\n\n let workspaceDependency: WorkspaceDependency = {\n name: dependencyName,\n versions: [dependencyVersion],\n exactVersions: [exactDependencyVersion],\n projects: [],\n };\n\n if (project.name) {\n workspaceDependency.projects = [\n {\n name: project.name,\n version: dependencyVersion,\n exactVersion: exactDependencyVersion,\n },\n ];\n }\n\n workspaceDependencies.push(workspaceDependency);\n }\n }\n\n if (options?.includeDevDependencies || options?.includeOnlyDevDependencies) {\n for (let [dependencyName, dependencyVersion] of Object.entries({\n ...project.packageJson.devDependencies,\n })) {\n let exactDependencyVersion =\n semver.validRange(dependencyVersion) ?\n (semver.minVersion(dependencyVersion)?.format() ??\n semver.coerce(dependencyVersion)?.format() ??\n dependencyVersion.trim())\n : dependencyVersion.trim();\n\n let workspaceDependency: WorkspaceDependency = {\n name: dependencyName,\n versions: [dependencyVersion],\n exactVersions: [exactDependencyVersion],\n projects: [],\n };\n\n if (project.name) {\n workspaceDependency.projects = [\n {\n name: project.name,\n version: dependencyVersion,\n exactVersion: exactDependencyVersion,\n },\n ];\n }\n\n workspaceDependencies.push(workspaceDependency);\n }\n }\n }\n\n return new this(...workspaceDependencies, workspace);\n }\n\n /**\n * Creates map of all dependnecies and their installed version.\n *\n * @param options Options.\n * @returns Object whose keys are dependency names and values are sorted versions.\n */\n getVersions(options?: WorkspaceDependenciesGetVersionsOptions) {\n let versions: Record<string, string[]> = {};\n\n for (let dependency of this) {\n versions[dependency.name] =\n options?.useExactVersions ? dependency.exactVersions : dependency.versions;\n }\n\n return versions;\n }\n}\n"],
|
|
5
|
-
"mappings": "AAAA,OAAO,OAAO;AACd,OAAO,YAAY;AAEnB,SAAQ,eAAe,6CAA4C;
|
|
4
|
+
"sourcesContent": ["import _ from 'lodash';\nimport semver from 'semver';\n\nimport {compareSemver, compareWorkspaceDependencyProjectName} from './internals.js';\nimport {type Workspace} from './Workspace.js';\nimport {type WorkspaceDependenciesFromWorkspaceOptions} from './WorkspaceDependenciesFromWorkspaceOptions.js';\nimport {type WorkspaceDependenciesGetVersionsOptions} from './WorkspaceDependenciesGetVersionsOptions.js';\nimport {type WorkspaceDependency} from './WorkspaceDependency.js';\n\n/**\n * A collection of {@link WorkspaceDependency | workspace dependencies} that are installed in\n * {@link Workspace | a workspace}.\n */\nexport class WorkspaceDependencies<M extends boolean = true> extends Array<WorkspaceDependency> {\n /** The workspace the dependencies are installed in. */\n workspace: Workspace<M>;\n\n constructor(...args: [...WorkspaceDependency[], Workspace<M>]) {\n super();\n\n if (args.length === 1) {\n [this.workspace] = args as [Workspace<M>];\n } else {\n let values = args.slice(0, -1) as WorkspaceDependency[];\n let workspace = args.at(-1) as Workspace<M>;\n\n this.push(...values);\n\n this.workspace = workspace;\n }\n }\n\n /**\n * Adds one or more new dependencies.\n *\n * @param newWorkspaceDependencies The dependencies to add.\n * @returns The new length of the collection.\n */\n override push(...newWorkspaceDependencies: WorkspaceDependency[]): number {\n for (let newWorkspaceDependency of newWorkspaceDependencies) {\n let doesExist = false;\n\n for (let workspaceDependency of this) {\n if (workspaceDependency.name === newWorkspaceDependency.name) {\n doesExist = true;\n\n workspaceDependency.versions = _.union(\n workspaceDependency.versions,\n newWorkspaceDependency.versions,\n );\n workspaceDependency.exactVersions = _.union(\n workspaceDependency.exactVersions,\n newWorkspaceDependency.exactVersions,\n );\n workspaceDependency.projects = _.unionWith(\n workspaceDependency.projects,\n newWorkspaceDependency.projects,\n (a, b) => a.name === b.name,\n );\n\n workspaceDependency.versions.sort(compareSemver);\n workspaceDependency.exactVersions.sort(compareSemver);\n workspaceDependency.projects.sort(compareWorkspaceDependencyProjectName);\n }\n }\n\n if (!doesExist) {\n super.push(newWorkspaceDependency);\n }\n }\n\n return this.length;\n }\n\n /**\n * Creates new {@link WorkspaceDependencies} instance from a {@link Workspace} instance and its\n * dependencies.\n *\n * @param workspace The workspace from which the dependnecies are taken.\n * @param options Options.\n * @returns The new {@link WorkspaceDependencies} instance.\n */\n static fromWorkspace<M extends boolean = true>(\n workspace: Workspace<M>,\n options?: WorkspaceDependenciesFromWorkspaceOptions,\n ) {\n let workspaceDependencies: WorkspaceDependency[] = [];\n\n if (options?.includeWorkspaceDependencies) {\n for (let [dependencyName, dependencyVersion] of Object.entries({\n ...workspace.packageJson?.dependencies,\n ...workspace.packageJson?.devDependencies,\n ...(workspace.packageJson?.engines as Record<string, string>),\n })) {\n let exactDependencyVersion =\n semver.validRange(dependencyVersion) ?\n (semver.minVersion(dependencyVersion)?.format() ??\n semver.coerce(dependencyVersion)?.format() ??\n dependencyVersion.trim())\n : dependencyVersion.trim();\n\n let workspaceDependency: WorkspaceDependency = {\n name: dependencyName,\n versions: [dependencyVersion],\n exactVersions: [exactDependencyVersion],\n projects: [],\n };\n\n workspaceDependencies.push(workspaceDependency);\n }\n }\n\n for (let project of workspace.projects) {\n if (!options?.includeOnlyDevDependencies) {\n for (let [dependencyName, dependencyVersion] of Object.entries({\n ...project.packageJson.dependencies,\n ...(workspace.packageJson?.engines as Record<string, string>),\n })) {\n let exactDependencyVersion =\n semver.validRange(dependencyVersion) ?\n (semver.minVersion(dependencyVersion)?.format() ??\n semver.coerce(dependencyVersion)?.format() ??\n dependencyVersion.trim())\n : dependencyVersion.trim();\n\n let workspaceDependency: WorkspaceDependency = {\n name: dependencyName,\n versions: [dependencyVersion],\n exactVersions: [exactDependencyVersion],\n projects: [],\n };\n\n if (project.name) {\n workspaceDependency.projects = [\n {\n name: project.name,\n version: dependencyVersion,\n exactVersion: exactDependencyVersion,\n },\n ];\n }\n\n workspaceDependencies.push(workspaceDependency);\n }\n }\n\n if (options?.includeDevDependencies || options?.includeOnlyDevDependencies) {\n for (let [dependencyName, dependencyVersion] of Object.entries({\n ...project.packageJson.devDependencies,\n })) {\n let exactDependencyVersion =\n semver.validRange(dependencyVersion) ?\n (semver.minVersion(dependencyVersion)?.format() ??\n semver.coerce(dependencyVersion)?.format() ??\n dependencyVersion.trim())\n : dependencyVersion.trim();\n\n let workspaceDependency: WorkspaceDependency = {\n name: dependencyName,\n versions: [dependencyVersion],\n exactVersions: [exactDependencyVersion],\n projects: [],\n };\n\n if (project.name) {\n workspaceDependency.projects = [\n {\n name: project.name,\n version: dependencyVersion,\n exactVersion: exactDependencyVersion,\n },\n ];\n }\n\n workspaceDependencies.push(workspaceDependency);\n }\n }\n }\n\n return new this(...workspaceDependencies, workspace);\n }\n\n /**\n * Creates map of all dependnecies and their installed version.\n *\n * @param options Options.\n * @returns Object whose keys are dependency names and values are sorted versions.\n */\n getVersions(options?: WorkspaceDependenciesGetVersionsOptions) {\n let versions: Record<string, string[]> = {};\n\n for (let dependency of this) {\n versions[dependency.name] =\n options?.useExactVersions ? dependency.exactVersions : dependency.versions;\n }\n\n return versions;\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,OAAO;AACd,OAAO,YAAY;AAEnB,SAAQ,eAAe,6CAA4C;AAU5D,aAAM,8BAAwD,MAA2B;AAAA;AAAA,EAE9F;AAAA,EAEA,eAAe,MAAgD;AAC7D,UAAM;AAEN,QAAI,KAAK,WAAW,GAAG;AACrB,OAAC,KAAK,SAAS,IAAI;AAAA,IACrB,OAAO;AACL,UAAI,SAAS,KAAK,MAAM,GAAG,EAAE;AAC7B,UAAI,YAAY,KAAK,GAAG,EAAE;AAE1B,WAAK,KAAK,GAAG,MAAM;AAEnB,WAAK,YAAY;AAAA,IACnB;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQS,QAAQ,0BAAyD;AACxE,aAAS,0BAA0B,0B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AAChB,gCAAoB,WAAW;AAAA,cAC7B;AAAA,gBACE,MAAM,QAAQ;AAAA,gBACd,SAAS;AAAA,gBACT,cAAc;AAAA,cAChB;AAAA,YACF;AAAA,UACF;AAEA,gCAAsB,KAAK,mBAAmB;AAAA,QAChD;AAAA,MACF;AAAA,IACF;AAEA,WAAO,IAAI,KAAK,GAAG,uBAAuB,SAAS;AAAA,EACrD;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQA,YAAY,SAAmD;AAC7D,QAAI,WAAqC,CAAC;AAE1C,aAAS,cAAc,MAAM;AAC3B,eAAS,WAAW,IAAI,IACtB,SAAS,mBAAmB,WAAW,gBAAgB,WAAW;AAAA,IACtE;AAEA,WAAO;AAAA,EACT;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* {@link WorkspaceDependencies.fromWorkspace | WorkspaceDependencies.fromWorkspace} options
|
|
2
|
+
* {@link WorkspaceDependencies.fromWorkspace | WorkspaceDependencies.fromWorkspace} options
|
|
3
|
+
* parameter.
|
|
3
4
|
*/
|
|
4
5
|
export type WorkspaceDependenciesFromWorkspaceOptions = {
|
|
5
6
|
includeDevDependencies?: boolean;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type WorkspaceDependencyProject } from './WorkspaceDependencyProject.js';
|
|
2
2
|
/**
|
|
3
|
-
* Dependency is an external piece of software (e.g. a package) that is installed in a {@link
|
|
3
|
+
* Dependency is an external piece of software (e.g. a package) that is installed in a {@link
|
|
4
|
+
* Workspace | a workspace} and usually required by one or more of its {@link Project | projects}.
|
|
4
5
|
*/
|
|
5
6
|
export type WorkspaceDependency = {
|
|
6
7
|
/** Dependency name. */
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
export type WorkspaceDependencyProject = {
|
|
5
5
|
/** Project name. */
|
|
6
6
|
name: string;
|
|
7
|
-
/** SemVer version range of the dependency that is actually
|
|
7
|
+
/** SemVer version range of the dependency that is actually required by the project. */
|
|
8
8
|
version: string;
|
|
9
9
|
/** Exact version of the dependency that is actually is actually required by the project. */
|
|
10
10
|
exactVersion: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jakubmazanec/carson",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.7-unstable.72f063e3",
|
|
4
4
|
"description": "Tool for managing workspace and project configuration.",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,12 +32,12 @@
|
|
|
32
32
|
"typecheck": "tsc --project tsconfig.typecheck.json"
|
|
33
33
|
},
|
|
34
34
|
"dependencies": {
|
|
35
|
-
"@jakubmazanec/args": "
|
|
36
|
-
"@jakubmazanec/cli": "
|
|
37
|
-
"@jakubmazanec/error": "
|
|
38
|
-
"@jakubmazanec/fs-utils": "
|
|
39
|
-
"@jakubmazanec/template": "
|
|
40
|
-
"@jakubmazanec/ts-utils": "
|
|
35
|
+
"@jakubmazanec/args": "2.0.19-unstable.72f063e3",
|
|
36
|
+
"@jakubmazanec/cli": "0.5.7-unstable.72f063e3",
|
|
37
|
+
"@jakubmazanec/error": "3.0.19-unstable.72f063e3",
|
|
38
|
+
"@jakubmazanec/fs-utils": "0.2.19-unstable.72f063e3",
|
|
39
|
+
"@jakubmazanec/template": "2.0.20-unstable.72f063e3",
|
|
40
|
+
"@jakubmazanec/ts-utils": "3.0.20-unstable.72f063e3",
|
|
41
41
|
"@jakubmazanec/zod-utils": "^3.0.0",
|
|
42
42
|
"chalk": "^5.6.2",
|
|
43
43
|
"fast-glob": "^3.3.3",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"zod": "^4.4.3"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
|
-
"@jakubmazanec/eslint-config": "
|
|
57
|
+
"@jakubmazanec/eslint-config": "6.0.0-unstable.72f063e3",
|
|
58
58
|
"@types/fs-extra": "^11.0.4",
|
|
59
59
|
"@types/lodash": "^4.17.24",
|
|
60
60
|
"@types/node": "^24.0.4",
|
|
@@ -34,7 +34,8 @@ export function runCreateProject({
|
|
|
34
34
|
|
|
35
35
|
observer.next('Updating the new project');
|
|
36
36
|
|
|
37
|
-
// if the project doesn't have config with a template ID, it's on purpose, but it's still
|
|
37
|
+
// if the project doesn't have config with a template ID, it's on purpose, but it's still
|
|
38
|
+
// needed for the next update, so we'll add it manually
|
|
38
39
|
project.config.template ??= templateId;
|
|
39
40
|
|
|
40
41
|
await project.update({args});
|
|
@@ -25,7 +25,8 @@ export function runCreateWorkspace({workspacePath, templateId, args}: CreateWork
|
|
|
25
25
|
|
|
26
26
|
observer.next('Updating the new workspace');
|
|
27
27
|
|
|
28
|
-
// if the workspace doesn't have config with a template ID, it's on purpose, but it's still
|
|
28
|
+
// if the workspace doesn't have config with a template ID, it's on purpose, but it's still
|
|
29
|
+
// needed for the next update, so we'll add it manually
|
|
29
30
|
workspace.config.template ??= templateId;
|
|
30
31
|
|
|
31
32
|
await workspace.update({args});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {z} from 'zod';
|
|
2
2
|
|
|
3
|
-
// TODO: add strategy 'none' so when you using template A that extends template B, you can
|
|
3
|
+
// TODO: add strategy 'none' so when you using template A that extends template B, you can
|
|
4
|
+
// overwrite template files to no-op
|
|
4
5
|
let strategyTemplateAttributeSchema = z.union([
|
|
5
6
|
z.literal('create'),
|
|
6
7
|
z.literal('ensure'),
|
|
@@ -3,7 +3,8 @@ import {z} from 'zod';
|
|
|
3
3
|
import {Project} from '../workspace/Project.js';
|
|
4
4
|
import {Workspace} from '../workspace/Workspace.js';
|
|
5
5
|
|
|
6
|
-
// TODO: what about template data for workspace and template data for project, so we can get rid of
|
|
6
|
+
// TODO: what about template data for workspace and template data for project, so we can get rid of
|
|
7
|
+
// the `.optional()`?
|
|
7
8
|
export const templateDataSchema = z
|
|
8
9
|
.object({
|
|
9
10
|
workspace: z.instanceof(Workspace).optional(),
|
|
@@ -25,7 +25,8 @@ export type ApplyTemplateRendersOptions = {
|
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
/**
|
|
28
|
-
* Applies rendered Carson template to a specified path, i.e. creates and updates files based on
|
|
28
|
+
* Applies rendered Carson template to a specified path, i.e. creates and updates files based on
|
|
29
|
+
* the result of rendering each Carson template file.
|
|
29
30
|
*/
|
|
30
31
|
export async function applyTemplateRenders({
|
|
31
32
|
templateRenders,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Simplifies JSON for usage in snapshots: string, number or boolean values are replaced with
|
|
2
|
+
* Simplifies JSON for usage in snapshots: string, number or boolean values are replaced with
|
|
3
|
+
* `null`.
|
|
3
4
|
*/
|
|
4
5
|
export function simplify(a: unknown) {
|
|
5
6
|
if (a === undefined || a == null) {
|
|
@@ -22,7 +22,8 @@ import {saveProjectConfig} from './saveProjectConfig.js';
|
|
|
22
22
|
import {type Workspace} from './Workspace.js';
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* Project represent a self-contained piece of software (e.g. a package, or an app) that is part of
|
|
25
|
+
* Project represent a self-contained piece of software (e.g. a package, or an app) that is part of
|
|
26
|
+
* a {@link Workspace}. Currently only Node.js projects are supported.
|
|
26
27
|
*
|
|
27
28
|
* @typeParam M If true, the project belongs to a multi-project workspace.
|
|
28
29
|
*/
|
|
@@ -56,7 +57,8 @@ export class Project<M extends boolean = true> {
|
|
|
56
57
|
workspace,
|
|
57
58
|
errors,
|
|
58
59
|
}: ProjectOptions<M>) {
|
|
59
|
-
// TODO: check that this path and workspace path are correct, i.e. project path must always be
|
|
60
|
+
// TODO: check that this path and workspace path are correct, i.e. project path must always be
|
|
61
|
+
// inside of workspace path
|
|
60
62
|
this.path = projectPath;
|
|
61
63
|
|
|
62
64
|
if (name) {
|
|
@@ -104,7 +106,8 @@ export class Project<M extends boolean = true> {
|
|
|
104
106
|
workspace,
|
|
105
107
|
});
|
|
106
108
|
|
|
107
|
-
// if the workspace is single-project, it shares a directory with the project, so we can't
|
|
109
|
+
// if the workspace is single-project, it shares a directory with the project, so we can't
|
|
110
|
+
// insist on it being an empty directory
|
|
108
111
|
if (workspace.isMultiProject) {
|
|
109
112
|
try {
|
|
110
113
|
await ensureEmptyDirectory(project.path);
|
|
@@ -41,7 +41,8 @@ import {type WorkspaceRepository} from './WorkspaceRepository.js';
|
|
|
41
41
|
import {type WorkspaceUpdateOptions} from './WorkspaceUpdateOptions.js';
|
|
42
42
|
|
|
43
43
|
/**
|
|
44
|
-
* Workspace represent a directory, usually a git repository, that contains {@link Project}
|
|
44
|
+
* Workspace represent a directory, usually a git repository, that contains {@link Project}
|
|
45
|
+
* instances.
|
|
45
46
|
*
|
|
46
47
|
* @typeParam M If true, the workspace is multi-project workspace (so-called "monorepo").
|
|
47
48
|
*/
|
|
@@ -61,7 +62,10 @@ export class Workspace<M extends boolean = true> {
|
|
|
61
62
|
/** Workspace configuration; if it's not found, the default is an empty object. */
|
|
62
63
|
config: WorkspaceConfig;
|
|
63
64
|
|
|
64
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* Parsed workspace `package.json` file (if the workspace contains multiple projects); if it's
|
|
67
|
+
* not found, the default is an empty object.
|
|
68
|
+
*/
|
|
65
69
|
packageJson: WorkspacePackageJson<M>;
|
|
66
70
|
|
|
67
71
|
/** Workspace git repository. */
|
|
@@ -164,7 +168,8 @@ export class Workspace<M extends boolean = true> {
|
|
|
164
168
|
* @returns The new workspace.
|
|
165
169
|
*/
|
|
166
170
|
static async create({args, path: workspacePath, templateId}: WorkspaceCreateOptions) {
|
|
167
|
-
// TODO: test that workspace returned by this method has the same value of isMultiProject when
|
|
171
|
+
// TODO: test that workspace returned by this method has the same value of isMultiProject when
|
|
172
|
+
// the same workspace is after its creation re-read with .read()
|
|
168
173
|
let workspace = new this({
|
|
169
174
|
path: workspacePath,
|
|
170
175
|
config: {
|
|
@@ -324,7 +329,8 @@ export class Workspace<M extends boolean = true> {
|
|
|
324
329
|
}
|
|
325
330
|
|
|
326
331
|
/**
|
|
327
|
-
* Traverses file system up from the search path and tries to find a directory that is a root of
|
|
332
|
+
* Traverses file system up from the search path and tries to find a directory that is a root of
|
|
333
|
+
* a workspace.
|
|
328
334
|
*
|
|
329
335
|
* @param searchPath Search path.
|
|
330
336
|
* @returns Workspace path, if found.
|
|
@@ -8,7 +8,8 @@ import {type WorkspaceDependenciesGetVersionsOptions} from './WorkspaceDependenc
|
|
|
8
8
|
import {type WorkspaceDependency} from './WorkspaceDependency.js';
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
|
-
* A collection of {@link WorkspaceDependency | workspace dependencies} that are installed in
|
|
11
|
+
* A collection of {@link WorkspaceDependency | workspace dependencies} that are installed in
|
|
12
|
+
* {@link Workspace | a workspace}.
|
|
12
13
|
*/
|
|
13
14
|
export class WorkspaceDependencies<M extends boolean = true> extends Array<WorkspaceDependency> {
|
|
14
15
|
/** The workspace the dependencies are installed in. */
|
|
@@ -72,7 +73,8 @@ export class WorkspaceDependencies<M extends boolean = true> extends Array<Works
|
|
|
72
73
|
}
|
|
73
74
|
|
|
74
75
|
/**
|
|
75
|
-
* Creates new {@link WorkspaceDependencies} instance from a {@link Workspace} instance and its
|
|
76
|
+
* Creates new {@link WorkspaceDependencies} instance from a {@link Workspace} instance and its
|
|
77
|
+
* dependencies.
|
|
76
78
|
*
|
|
77
79
|
* @param workspace The workspace from which the dependnecies are taken.
|
|
78
80
|
* @param options Options.
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* {@link WorkspaceDependencies.fromWorkspace | WorkspaceDependencies.fromWorkspace} options
|
|
2
|
+
* {@link WorkspaceDependencies.fromWorkspace | WorkspaceDependencies.fromWorkspace} options
|
|
3
|
+
* parameter.
|
|
3
4
|
*/
|
|
4
5
|
export type WorkspaceDependenciesFromWorkspaceOptions = {
|
|
5
6
|
includeDevDependencies?: boolean;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import {type WorkspaceDependencyProject} from './WorkspaceDependencyProject.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
* Dependency is an external piece of software (e.g. a package) that is installed in a {@link
|
|
4
|
+
* Dependency is an external piece of software (e.g. a package) that is installed in a {@link
|
|
5
|
+
* Workspace | a workspace} and usually required by one or more of its {@link Project | projects}.
|
|
5
6
|
*/
|
|
6
7
|
export type WorkspaceDependency = {
|
|
7
8
|
/** Dependency name. */
|
|
@@ -5,7 +5,7 @@ export type WorkspaceDependencyProject = {
|
|
|
5
5
|
/** Project name. */
|
|
6
6
|
name: string;
|
|
7
7
|
|
|
8
|
-
/** SemVer version range of the dependency that is actually
|
|
8
|
+
/** SemVer version range of the dependency that is actually required by the project. */
|
|
9
9
|
version: string;
|
|
10
10
|
|
|
11
11
|
/** Exact version of the dependency that is actually is actually required by the project. */
|