@quilted/create 0.1.36 → 0.1.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/build/cjs/app.cjs +17 -21
- package/build/cjs/index4.cjs +7635 -0
- package/build/cjs/package.cjs +162 -65
- package/build/cjs/shared/package-manager.cjs +57 -7
- package/build/esm/app.mjs +18 -22
- package/build/esm/index4.mjs +7626 -0
- package/build/esm/package.mjs +164 -67
- package/build/esm/shared/package-manager.mjs +57 -8
- package/build/tsconfig.tsbuildinfo +1 -1
- package/build/typescript/app.d.ts.map +1 -1
- package/build/typescript/package.d.ts.map +1 -1
- package/build/typescript/shared/prompts.d.ts +9 -2
- package/build/typescript/shared/prompts.d.ts.map +1 -1
- package/build/typescript/shared.d.ts +1 -0
- package/build/typescript/shared.d.ts.map +1 -1
- package/package.json +2 -1
- package/source/app.ts +20 -28
- package/source/package.ts +239 -101
- package/source/shared/prompts.ts +21 -6
- package/source/shared.ts +68 -7
- package/templates/package/README.md +1 -1
- package/templates/package/quilt.project.ts +1 -1
- package/templates/workspace/_nvmrc +1 -1
- package/templates/workspace/package.json +4 -0
package/build/esm/package.mjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as fs from 'node:fs';
|
|
2
2
|
import * as path from 'node:path';
|
|
3
|
-
import { s as stripIndent, c as cyan_1,
|
|
4
|
-
import { g as
|
|
3
|
+
import { s as stripIndent, c as cyan_1, d as dim_1, p as printHelp, b as bold_1, u as underline_1, m as magenta_1, e as parseArguments, a as prompt } from './index.mjs';
|
|
4
|
+
import { g as getInWorkspace, a as getCreateAsMonorepo, d as getExtrasToSetup, e as getShouldInstall, f as getPackageManager, t as toValidPackageName, h as emptyDirectory, r as relativeDirectoryForDisplay, i as format, m as mergeWorkspaceAndProjectPackageJsons, l as loadTemplate, j as addToTsConfig, k as addToPackageManagerWorkspaces, p as isEmpty, q as createOutputTarget } from './shared/package-manager.mjs';
|
|
5
5
|
import 'node:tty';
|
|
6
6
|
import 'node:readline';
|
|
7
7
|
import 'node:events';
|
|
@@ -12,6 +12,11 @@ async function createProject() {
|
|
|
12
12
|
const args = getArguments();
|
|
13
13
|
if (args['--help']) {
|
|
14
14
|
const additionalOptions = stripIndent`
|
|
15
|
+
${cyan_1(`--description`)}, ${cyan_1(`--no-description`)}
|
|
16
|
+
A short description of the package. If you don’t provide this option, the command will ask
|
|
17
|
+
you for a description later.
|
|
18
|
+
${dim_1(`@see https://docs.npmjs.com/cli/v9/configuring-npm/package-json#description`)}
|
|
19
|
+
|
|
15
20
|
${cyan_1(`--react`)}, ${cyan_1(`--no-react`)}
|
|
16
21
|
Whether this package will use React. If you don’t provide this option, the command
|
|
17
22
|
will ask you about it later.
|
|
@@ -20,6 +25,11 @@ async function createProject() {
|
|
|
20
25
|
Whether this package will be published for other projects to install. If you do not
|
|
21
26
|
provide this option, the command will ask you about it later.
|
|
22
27
|
|
|
28
|
+
${cyan_1(`--repository`)}, ${cyan_1(`--no-repository`)}
|
|
29
|
+
The URL of a git repository where your code lives. If you do not provide this option,
|
|
30
|
+
this command will try to guess the correct repository to use based on existing packages.
|
|
31
|
+
${dim_1(`@see https://docs.npmjs.com/cli/v9/configuring-npm/package-json#repository`)}
|
|
32
|
+
|
|
23
33
|
${cyan_1(`--registry`)}
|
|
24
34
|
The package registry to publish this package to. This option only applies if you create
|
|
25
35
|
a public package. If you do not provide this option, it will use the default NPM registry.
|
|
@@ -31,22 +41,30 @@ async function createProject() {
|
|
|
31
41
|
});
|
|
32
42
|
return;
|
|
33
43
|
}
|
|
34
|
-
const inWorkspace = fs.existsSync('quilt.workspace.ts');
|
|
35
44
|
const name = await getName(args);
|
|
45
|
+
const description = await getDescription(args);
|
|
46
|
+
const inWorkspace = await getInWorkspace(args);
|
|
36
47
|
const directory = await getDirectory(args, {
|
|
37
48
|
name,
|
|
38
49
|
inWorkspace
|
|
39
50
|
});
|
|
40
51
|
const isPublic = await getPublic(args);
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
const shouldInstall = await getShouldInstall(args);
|
|
44
|
-
const packageManager = await getPackageManager(args, {
|
|
45
|
-
root: directory
|
|
52
|
+
const repository = await getRepository(args, {
|
|
53
|
+
inWorkspace
|
|
46
54
|
});
|
|
55
|
+
const useReact = await getReact(args);
|
|
56
|
+
const createAsMonorepo = !inWorkspace && (await getCreateAsMonorepo(args, {
|
|
57
|
+
type: 'package'
|
|
58
|
+
}));
|
|
47
59
|
const setupExtras = await getExtrasToSetup(args, {
|
|
48
60
|
inWorkspace
|
|
49
61
|
});
|
|
62
|
+
const shouldInstall = await getShouldInstall(args, {
|
|
63
|
+
type: 'package'
|
|
64
|
+
});
|
|
65
|
+
const packageManager = await getPackageManager(args, {
|
|
66
|
+
root: directory
|
|
67
|
+
});
|
|
50
68
|
const partOfMonorepo = inWorkspace || createAsMonorepo;
|
|
51
69
|
const packageDirectory = createAsMonorepo ? path.join(directory, `packages/${toValidPackageName(name.split('/').pop())}`) : directory;
|
|
52
70
|
if (fs.existsSync(directory)) {
|
|
@@ -66,12 +84,15 @@ async function createProject() {
|
|
|
66
84
|
const packageTemplate = loadTemplate('package');
|
|
67
85
|
const workspaceTemplate = loadTemplate('workspace');
|
|
68
86
|
let quiltProject = await packageTemplate.read('quilt.project.ts');
|
|
87
|
+
if (!useReact) {
|
|
88
|
+
quiltProject = quiltProject.replace('quiltPackage()', 'quiltPackage({react: false})');
|
|
89
|
+
}
|
|
69
90
|
|
|
70
91
|
// If we aren’t already in a workspace, copy the workspace files over, which
|
|
71
92
|
// are needed if we are making a monorepo or not.
|
|
72
93
|
if (!inWorkspace) {
|
|
73
94
|
await workspaceTemplate.copy(directory, file => {
|
|
74
|
-
// When this is a single project, we use the project’s Quilt
|
|
95
|
+
// When this is a single project, we use the project’s Quilt configuration as the base.
|
|
75
96
|
if (file === 'quilt.workspace.ts') return createAsMonorepo;
|
|
76
97
|
|
|
77
98
|
// We need to make some adjustments to the root package.json
|
|
@@ -81,41 +102,28 @@ async function createProject() {
|
|
|
81
102
|
// If we are creating a monorepo, we need to add the root package.json and
|
|
82
103
|
// package manager workspace configuration.
|
|
83
104
|
if (createAsMonorepo) {
|
|
105
|
+
const packageRelativeToRoot = path.relative(rootDirectory, packageDirectory);
|
|
106
|
+
const packageGlobRelativeToRoot = relativeDirectoryForDisplay(path.join(packageRelativeToRoot, '*'));
|
|
84
107
|
const workspacePackageJson = JSON.parse(await workspaceTemplate.read('package.json'));
|
|
85
108
|
workspacePackageJson.name = toValidPackageName(name);
|
|
109
|
+
workspacePackageJson.workspaces = [packageGlobRelativeToRoot];
|
|
86
110
|
if (packageManager.type === 'pnpm') {
|
|
87
111
|
await outputRoot.write('pnpm-workspace.yaml', await format(`
|
|
88
112
|
packages:
|
|
89
|
-
- '
|
|
113
|
+
- '${packageGlobRelativeToRoot}'
|
|
90
114
|
`, {
|
|
91
115
|
as: 'yaml'
|
|
92
116
|
}));
|
|
93
|
-
} else {
|
|
94
|
-
workspacePackageJson.workspaces = ['packages/*'];
|
|
95
117
|
}
|
|
96
118
|
await outputRoot.write('package.json', await format(JSON.stringify(workspacePackageJson), {
|
|
97
119
|
as: 'json-stringify'
|
|
98
120
|
}));
|
|
99
121
|
} else {
|
|
100
122
|
const [projectPackageJson, projectTSConfig, workspacePackageJson] = await Promise.all([packageTemplate.read('package.json').then(content => JSON.parse(content)), packageTemplate.read('tsconfig.json').then(content => JSON.parse(content)), workspaceTemplate.read('package.json').then(content => JSON.parse(content))]);
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
const newPackageJson = {};
|
|
104
|
-
|
|
105
|
-
// We want to put the project’s dependencies in the package.json, respecting
|
|
106
|
-
// the preferred ordering (dependencies, peer dependencies, dev dependencies).
|
|
107
|
-
for (const [key, value] of Object.entries(projectPackageJson)) {
|
|
108
|
-
if (key !== 'devDependencies') {
|
|
109
|
-
newPackageJson[key] = value;
|
|
110
|
-
continue;
|
|
111
|
-
}
|
|
112
|
-
newPackageJson.dependencies = projectPackageJson.dependencies;
|
|
113
|
-
newPackageJson.peerDependencies = projectPackageJson.peerDependencies;
|
|
114
|
-
newPackageJson.peerDependenciesMeta = projectPackageJson.peerDependenciesMeta;
|
|
115
|
-
newPackageJson.devDependencies = mergeDependencies(workspacePackageJson.devDependencies, projectPackageJson.devDependencies);
|
|
116
|
-
}
|
|
117
|
-
adjustPackageJson(newPackageJson, {
|
|
123
|
+
const mergedPackageJson = mergeWorkspaceAndProjectPackageJsons(projectPackageJson, workspacePackageJson);
|
|
124
|
+
adjustPackageJson(mergedPackageJson, {
|
|
118
125
|
name: toValidPackageName(name),
|
|
126
|
+
description,
|
|
119
127
|
react: useReact,
|
|
120
128
|
isPublic,
|
|
121
129
|
registry: args['--registry']
|
|
@@ -124,7 +132,7 @@ async function createProject() {
|
|
|
124
132
|
await outputRoot.write('quilt.project.ts', await format(quiltProject, {
|
|
125
133
|
as: 'typescript'
|
|
126
134
|
}));
|
|
127
|
-
await outputRoot.write('package.json', await format(JSON.stringify(
|
|
135
|
+
await outputRoot.write('package.json', await format(JSON.stringify(mergedPackageJson), {
|
|
128
136
|
as: 'json-stringify'
|
|
129
137
|
}));
|
|
130
138
|
await outputRoot.write('tsconfig.json', await format(JSON.stringify(projectTSConfig), {
|
|
@@ -144,15 +152,36 @@ async function createProject() {
|
|
|
144
152
|
return partOfMonorepo;
|
|
145
153
|
}
|
|
146
154
|
|
|
147
|
-
// We need to make some adjustments the project’s package.json and Quilt config
|
|
148
|
-
return file !== 'package.json' && file !== 'quilt.project.ts';
|
|
155
|
+
// We need to make some adjustments the project’s package.json, README, and Quilt config
|
|
156
|
+
return file !== 'package.json' && file !== 'quilt.project.ts' && file !== 'README.md';
|
|
149
157
|
});
|
|
158
|
+
await outputRoot.write(path.join(packageDirectory, 'package.json'), (await packageTemplate.read('README.md')).replaceAll('{{name}}', toValidPackageName(name)));
|
|
150
159
|
if (partOfMonorepo) {
|
|
151
160
|
// Write the package’s package.json (the root one was already created)
|
|
152
161
|
const projectPackageJson = JSON.parse(await packageTemplate.read('package.json'));
|
|
153
|
-
|
|
162
|
+
if (repository === false) {
|
|
163
|
+
delete projectPackageJson.repository;
|
|
164
|
+
} else {
|
|
165
|
+
const directory = path.relative(rootDirectory, packageDirectory);
|
|
166
|
+
if (typeof repository === 'string') {
|
|
167
|
+
projectPackageJson.repository = {
|
|
168
|
+
type: 'git',
|
|
169
|
+
url: repository,
|
|
170
|
+
directory
|
|
171
|
+
};
|
|
172
|
+
} else if (repository != null) {
|
|
173
|
+
projectPackageJson.repository = {
|
|
174
|
+
type: 'git',
|
|
175
|
+
...repository,
|
|
176
|
+
directory
|
|
177
|
+
};
|
|
178
|
+
} else {
|
|
179
|
+
projectPackageJson.repository.directory = directory;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
154
182
|
adjustPackageJson(projectPackageJson, {
|
|
155
183
|
name: toValidPackageName(name),
|
|
184
|
+
description,
|
|
156
185
|
react: useReact,
|
|
157
186
|
isPublic,
|
|
158
187
|
registry: args['--registry']
|
|
@@ -164,45 +193,58 @@ async function createProject() {
|
|
|
164
193
|
await Promise.all([addToTsConfig(packageDirectory, outputRoot), addToPackageManagerWorkspaces(packageDirectory, outputRoot, packageManager.type)]);
|
|
165
194
|
}
|
|
166
195
|
if (shouldInstall) {
|
|
167
|
-
|
|
196
|
+
console.log();
|
|
168
197
|
// TODO: better loading, handle errors
|
|
169
198
|
await packageManager.install();
|
|
170
|
-
process.stdout.moveCursor(0, -1);
|
|
171
|
-
process.stdout.clearLine(1);
|
|
172
|
-
console.log('Installed dependencies.');
|
|
173
199
|
}
|
|
174
|
-
const packageJsonInstructions = stripIndent`
|
|
175
|
-
Your new package is ready to go! However, before you go too much further,
|
|
176
|
-
you should update the following fields in ${cyan_1(relativeDirectoryForDisplay(path.relative(process.cwd(), path.join(packageDirectory, 'package.json'))))}:
|
|
177
|
-
|
|
178
|
-
- ${bold_1(`"description"`)}, where you provide a description of what your package does
|
|
179
|
-
- ${bold_1(`"repository"`)}, where you should include the ${bold_1(`"url"`)} of your project’s repo
|
|
180
|
-
|
|
181
|
-
Before you publish your package, you will also want to update the ${bold_1(`"version"`)}
|
|
182
|
-
field in the package.json file.
|
|
183
|
-
`;
|
|
184
200
|
console.log();
|
|
185
|
-
console.log(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
console.log(whatsNext);
|
|
201
|
+
console.log(stripIndent`
|
|
202
|
+
Your new package, ${bold_1(name)}, is ready to go! You can edit the code
|
|
203
|
+
for your package in ${cyan_1(relativeDirectoryForDisplay(path.relative(process.cwd(), path.join(packageDirectory, 'source'))))}.
|
|
204
|
+
`);
|
|
205
|
+
if (isPublic) {
|
|
206
|
+
const needsPackageJsonKeys = [];
|
|
207
|
+
if (!description) {
|
|
208
|
+
needsPackageJsonKeys.push({
|
|
209
|
+
field: 'description',
|
|
210
|
+
url: 'https://docs.npmjs.com/cli/v9/configuring-npm/package-json#description'
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
if (repository == null) {
|
|
214
|
+
needsPackageJsonKeys.push({
|
|
215
|
+
field: 'repository.url',
|
|
216
|
+
url: 'https://docs.npmjs.com/cli/v9/configuring-npm/package-json#repository'
|
|
217
|
+
});
|
|
218
|
+
}
|
|
204
219
|
console.log();
|
|
205
|
-
|
|
220
|
+
const logPackageJsonField = (field, url) => {
|
|
221
|
+
console.log(` ${bold_1(JSON.stringify(field))} ${dim_1(`(${underline_1(url)})`)}`);
|
|
222
|
+
};
|
|
223
|
+
if (needsPackageJsonKeys.length > 0) {
|
|
224
|
+
console.log(stripIndent`
|
|
225
|
+
Before you publish your package, you will need to add the following key${needsPackageJsonKeys.length > 1 ? 's' : ''}
|
|
226
|
+
to ${cyan_1(relativeDirectoryForDisplay(path.relative(process.cwd(), path.join(packageDirectory, 'package.json'))))}:
|
|
227
|
+
`);
|
|
228
|
+
console.log();
|
|
229
|
+
for (const {
|
|
230
|
+
field,
|
|
231
|
+
url
|
|
232
|
+
} of needsPackageJsonKeys) {
|
|
233
|
+
logPackageJsonField(field, url);
|
|
234
|
+
}
|
|
235
|
+
console.log();
|
|
236
|
+
console.log('In that same file, make sure the contents of these fields are right for your package:');
|
|
237
|
+
console.log();
|
|
238
|
+
} else {
|
|
239
|
+
console.log(stripIndent`
|
|
240
|
+
Before you publish your package, make the following fields look right
|
|
241
|
+
in ${cyan_1(relativeDirectoryForDisplay(path.relative(process.cwd(), path.join(packageDirectory, 'package.json'))))}:
|
|
242
|
+
`);
|
|
243
|
+
console.log();
|
|
244
|
+
}
|
|
245
|
+
logPackageJsonField('version', 'https://docs.npmjs.com/cli/v9/configuring-npm/package-json#version');
|
|
246
|
+
logPackageJsonField('license', 'https://docs.npmjs.com/cli/v9/configuring-npm/package-json#license');
|
|
247
|
+
logPackageJsonField('exports', 'https://nodejs.org/api/packages.html#package-entry-points');
|
|
206
248
|
}
|
|
207
249
|
const followUp = stripIndent`
|
|
208
250
|
Quilt can help you build, test, lint, and type-check your new package. You
|
|
@@ -223,6 +265,10 @@ function getArguments() {
|
|
|
223
265
|
'-y': '--yes',
|
|
224
266
|
'--name': String,
|
|
225
267
|
'--directory': String,
|
|
268
|
+
'--description': String,
|
|
269
|
+
'--no-description': Boolean,
|
|
270
|
+
'--repository': String,
|
|
271
|
+
'--no-repository': Boolean,
|
|
226
272
|
'--install': Boolean,
|
|
227
273
|
'--no-install': Boolean,
|
|
228
274
|
'--monorepo': Boolean,
|
|
@@ -289,6 +335,36 @@ async function getDirectory(args, {
|
|
|
289
335
|
}
|
|
290
336
|
return directory;
|
|
291
337
|
}
|
|
338
|
+
async function getDescription(args) {
|
|
339
|
+
if (args['--description']) return args['--description'];
|
|
340
|
+
if (args['--no-description']) return false;
|
|
341
|
+
const description = await prompt({
|
|
342
|
+
type: 'text',
|
|
343
|
+
message: 'What is a short description of what this package will do?'
|
|
344
|
+
});
|
|
345
|
+
return description;
|
|
346
|
+
}
|
|
347
|
+
async function getRepository(args, {
|
|
348
|
+
inWorkspace = false
|
|
349
|
+
} = {}) {
|
|
350
|
+
if (args['--repository']) return args['--repository'];
|
|
351
|
+
if (args['--no-repository']) return false;
|
|
352
|
+
if (!inWorkspace) return;
|
|
353
|
+
const {
|
|
354
|
+
globby
|
|
355
|
+
} = await import('./index4.mjs');
|
|
356
|
+
const files = await globby('**/package.json', {
|
|
357
|
+
ignore: ['**/node_modules']
|
|
358
|
+
});
|
|
359
|
+
for (const file of files) {
|
|
360
|
+
try {
|
|
361
|
+
const json = JSON.parse(await fs.promises.readFile(file, 'utf8'));
|
|
362
|
+
if (json.repository) return json.repository;
|
|
363
|
+
} catch {
|
|
364
|
+
// noop
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
292
368
|
async function getPublic(args) {
|
|
293
369
|
let isPublic;
|
|
294
370
|
if (args['--public'] || args['--yes']) {
|
|
@@ -321,6 +397,7 @@ async function getReact(args) {
|
|
|
321
397
|
}
|
|
322
398
|
function adjustPackageJson(packageJson, {
|
|
323
399
|
name,
|
|
400
|
+
description,
|
|
324
401
|
react,
|
|
325
402
|
isPublic,
|
|
326
403
|
registry
|
|
@@ -329,6 +406,11 @@ function adjustPackageJson(packageJson, {
|
|
|
329
406
|
const packageParts = name.split('/');
|
|
330
407
|
const scope = packageParts[0].startsWith('@') ? packageParts[0] : undefined;
|
|
331
408
|
const finalRegistry = registry ?? 'https://registry.npmjs.org';
|
|
409
|
+
if (description) {
|
|
410
|
+
packageJson.description = description;
|
|
411
|
+
} else {
|
|
412
|
+
delete packageJson.description;
|
|
413
|
+
}
|
|
332
414
|
if (scope) {
|
|
333
415
|
packageJson.publishConfig[`${scope}/registry`] = finalRegistry;
|
|
334
416
|
} else if (registry) {
|
|
@@ -337,7 +419,22 @@ function adjustPackageJson(packageJson, {
|
|
|
337
419
|
if (isPublic) {
|
|
338
420
|
delete packageJson.private;
|
|
339
421
|
} else {
|
|
422
|
+
delete packageJson.license;
|
|
423
|
+
delete packageJson.repository;
|
|
340
424
|
delete packageJson.publishConfig;
|
|
425
|
+
|
|
426
|
+
// in private packages, we just need to reference the source.
|
|
427
|
+
const newExports = {};
|
|
428
|
+
for (const [key, value] of Object.entries(packageJson.exports)) {
|
|
429
|
+
if (typeof value === 'string') {
|
|
430
|
+
newExports[key] = value;
|
|
431
|
+
}
|
|
432
|
+
const sourceEntry = value?.['quilt:source'];
|
|
433
|
+
if (typeof sourceEntry === 'string') {
|
|
434
|
+
newExports[key] = sourceEntry;
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
packageJson.exports = newExports;
|
|
341
438
|
}
|
|
342
439
|
if (!react) {
|
|
343
440
|
delete packageJson.dependencies['@types/react'];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import require$$0 from 'node:tty';
|
|
2
|
-
import { a as prompt } from '../index.mjs';
|
|
3
1
|
import * as fs from 'node:fs';
|
|
4
2
|
import { existsSync } from 'node:fs';
|
|
3
|
+
import require$$0 from 'node:tty';
|
|
4
|
+
import { a as prompt } from '../index.mjs';
|
|
5
5
|
import { execSync } from 'node:child_process';
|
|
6
6
|
import * as path from 'node:path';
|
|
7
7
|
import { relative } from 'node:path';
|
|
@@ -155,7 +155,8 @@ async function format(content, {
|
|
|
155
155
|
as: parser
|
|
156
156
|
}) {
|
|
157
157
|
const [{
|
|
158
|
-
format
|
|
158
|
+
format: rootFormat,
|
|
159
|
+
default: prettier
|
|
159
160
|
}, {
|
|
160
161
|
default: babel
|
|
161
162
|
}, {
|
|
@@ -163,6 +164,9 @@ async function format(content, {
|
|
|
163
164
|
}, {
|
|
164
165
|
default: yaml
|
|
165
166
|
}] = await Promise.all([import('../standalone.mjs').then(function (n) { return n.s; }), import('../parser-babel.mjs').then(function (n) { return n.p; }), import('../parser-typescript.mjs').then(function (n) { return n.p; }), import('../parser-yaml.mjs').then(function (n) { return n.p; })]);
|
|
167
|
+
|
|
168
|
+
// CJS workaround
|
|
169
|
+
const format = rootFormat ?? prettier.format;
|
|
166
170
|
return format(content, {
|
|
167
171
|
arrowParens: 'always',
|
|
168
172
|
bracketSpacing: false,
|
|
@@ -183,6 +187,42 @@ function mergeDependencies(first = {}, second = {}) {
|
|
|
183
187
|
}
|
|
184
188
|
return merged;
|
|
185
189
|
}
|
|
190
|
+
const PACKAGE_JSON_DEPENDENCY_KEYS = new Set(['dependencies', 'devDependencies', 'peerDependencies', 'peerDependenciesMeta']);
|
|
191
|
+
|
|
192
|
+
// Merges a project and workspace package.json together, with the following nitpicky preferences:
|
|
193
|
+
//
|
|
194
|
+
// - Take all the project’s fields in the order they appear by default
|
|
195
|
+
// - Merge the relevant dependencies together
|
|
196
|
+
// - Projects don’t come with `scripts` by default, but that should go before the first dependency list
|
|
197
|
+
// - If there are other keys in the workspace package.json, they should go last, in the order they appeared
|
|
198
|
+
function mergeWorkspaceAndProjectPackageJsons(projectPackageJson, workspacePackageJson) {
|
|
199
|
+
const newPackageJson = {};
|
|
200
|
+
const seenKeys = new Set();
|
|
201
|
+
let hasHandledScriptsField = false;
|
|
202
|
+
for (const [key, value] of Object.entries(projectPackageJson)) {
|
|
203
|
+
seenKeys.add(key);
|
|
204
|
+
const isDependencyKey = PACKAGE_JSON_DEPENDENCY_KEYS.has(key);
|
|
205
|
+
if (key === 'scripts' || isDependencyKey && !hasHandledScriptsField) {
|
|
206
|
+
newPackageJson.scripts = {
|
|
207
|
+
...workspacePackageJson.scripts,
|
|
208
|
+
...projectPackageJson.scripts
|
|
209
|
+
};
|
|
210
|
+
hasHandledScriptsField = true;
|
|
211
|
+
}
|
|
212
|
+
if (isDependencyKey) {
|
|
213
|
+
newPackageJson[key] = mergeDependencies(value, workspacePackageJson[key]);
|
|
214
|
+
} else {
|
|
215
|
+
newPackageJson[key] = value;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
for (const [key, value] of Object.entries(workspacePackageJson)) {
|
|
219
|
+
if (seenKeys.has(key)) continue;
|
|
220
|
+
// Merged workspace + project package.json means we are not in a monorepo
|
|
221
|
+
if (key === 'workspaces') continue;
|
|
222
|
+
newPackageJson[key] = value;
|
|
223
|
+
}
|
|
224
|
+
return newPackageJson;
|
|
225
|
+
}
|
|
186
226
|
|
|
187
227
|
var colorette = {};
|
|
188
228
|
|
|
@@ -400,7 +440,14 @@ colorette.whiteBright = whiteBright;
|
|
|
400
440
|
colorette.yellow = yellow;
|
|
401
441
|
colorette.yellowBright = yellowBright;
|
|
402
442
|
|
|
403
|
-
async function
|
|
443
|
+
async function getInWorkspace(argv) {
|
|
444
|
+
if (argv['--in-workspace']) return true;
|
|
445
|
+
if (argv['--not-in-workspace']) return false;
|
|
446
|
+
return fs.existsSync('quilt.workspace.ts');
|
|
447
|
+
}
|
|
448
|
+
async function getCreateAsMonorepo(argv, {
|
|
449
|
+
type
|
|
450
|
+
}) {
|
|
404
451
|
let createAsMonorepo;
|
|
405
452
|
if (argv['--monorepo' ]) {
|
|
406
453
|
createAsMonorepo = true;
|
|
@@ -409,13 +456,15 @@ async function getCreateAsMonorepo(argv) {
|
|
|
409
456
|
} else {
|
|
410
457
|
createAsMonorepo = await prompt({
|
|
411
458
|
type: 'confirm',
|
|
412
|
-
message:
|
|
459
|
+
message: `Do you want to create this ${type} as a monorepo, with room for more projects?`,
|
|
413
460
|
initial: true
|
|
414
461
|
});
|
|
415
462
|
}
|
|
416
463
|
return createAsMonorepo;
|
|
417
464
|
}
|
|
418
|
-
async function getShouldInstall(argv
|
|
465
|
+
async function getShouldInstall(argv, {
|
|
466
|
+
type
|
|
467
|
+
}) {
|
|
419
468
|
let shouldInstall;
|
|
420
469
|
if (argv['--install'] || argv['--yes']) {
|
|
421
470
|
shouldInstall = true;
|
|
@@ -424,7 +473,7 @@ async function getShouldInstall(argv) {
|
|
|
424
473
|
} else {
|
|
425
474
|
shouldInstall = await prompt({
|
|
426
475
|
type: 'confirm',
|
|
427
|
-
message:
|
|
476
|
+
message: `Do you want to install dependencies for this ${type} after creating it?`,
|
|
428
477
|
initial: true
|
|
429
478
|
});
|
|
430
479
|
}
|
|
@@ -574,4 +623,4 @@ async function addToWorkspaces(relative, workspaces) {
|
|
|
574
623
|
return [...workspaces, pretty ? relativeDirectoryForDisplay(relative) : relative].sort((patternOne, patternTwo) => patternOne.localeCompare(patternTwo));
|
|
575
624
|
}
|
|
576
625
|
|
|
577
|
-
export {
|
|
626
|
+
export { getCreateAsMonorepo as a, bold_1 as b, cyan_1 as c, getExtrasToSetup as d, getShouldInstall as e, getPackageManager as f, getInWorkspace as g, emptyDirectory as h, format as i, addToTsConfig as j, addToPackageManagerWorkspaces as k, loadTemplate as l, mergeWorkspaceAndProjectPackageJsons as m, dim_1 as n, magenta_1 as o, isEmpty as p, createOutputTarget as q, relativeDirectoryForDisplay as r, toValidPackageName as t, underline_1 as u };
|