extension-create 4.1.39 → 4.1.40-canary.459.2c1ba7b
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/README.md +3 -3
- package/dist/lib/messages.d.ts +2 -0
- package/dist/lib/utils.d.ts +2 -2
- package/dist/module.cjs +151 -57
- package/dist/steps/import-external-template.d.ts +6 -1
- package/dist/test-template-javascript/.extension-create.json +2 -2
- package/dist/test-template-javascript/README.md +1 -1
- package/dist/test-template-javascript/extension-env.d.ts +5 -1
- package/dist/test-template-javascript/package.json +1 -1
- package/package.json +5 -5
- package/templates/README.md +1 -1
- package/templates/javascript/.mcp.json +14 -0
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
[npm-version-image]: https://img.shields.io/npm/v/extension-create.svg?color=
|
|
1
|
+
[npm-version-image]: https://img.shields.io/npm/v/extension-create.svg?color=0065e6
|
|
2
2
|
[npm-version-url]: https://www.npmjs.com/package/extension-create
|
|
3
|
-
[npm-downloads-image]: https://img.shields.io/npm/dm/extension-create.svg?color=
|
|
3
|
+
[npm-downloads-image]: https://img.shields.io/npm/dm/extension-create.svg?color=0065e6
|
|
4
4
|
[npm-downloads-url]: https://www.npmjs.com/package/extension-create
|
|
5
5
|
[action-image]: https://github.com/extension-js/extension.js/actions/workflows/ci.yml/badge.svg?branch=main
|
|
6
6
|
[action-url]: https://github.com/extension-js/extension.js/actions/workflows/ci.yml
|
|
@@ -53,7 +53,7 @@ Creates a new extension project with the specified configuration.
|
|
|
53
53
|
|
|
54
54
|
## Templates
|
|
55
55
|
|
|
56
|
-
Templates are sourced from the public
|
|
56
|
+
Templates are sourced from the public templates repository. Browse the catalog in the [Extension.js templates](https://github.com/extension-js/templates) and reference templates by name (for example, `content`, `content-react`, `content-vue`).
|
|
57
57
|
|
|
58
58
|
## License
|
|
59
59
|
|
package/dist/lib/messages.d.ts
CHANGED
|
@@ -24,6 +24,7 @@ export declare function templateOverrideFetchFailed(url: string, error: unknown)
|
|
|
24
24
|
export declare function templateDownloadFailed(templateName: string, error: unknown): string;
|
|
25
25
|
export declare function templateOfflineFallback(requestedTemplate: string, fallbackTemplate: string, error: unknown): string;
|
|
26
26
|
export declare function removedStaleTemplateLockfiles(fileNames: string[]): string;
|
|
27
|
+
export declare function droppedTemplateLinks(linkPaths: string[]): string;
|
|
27
28
|
export declare function initializingGitForRepository(projectName: string): string;
|
|
28
29
|
export declare function initializingGitSkipped(projectName: string, reason: string): string;
|
|
29
30
|
export declare function firstCommitSkipped(projectName: string, reason: string): string;
|
|
@@ -55,4 +56,5 @@ export declare function writingGitIgnore(): string;
|
|
|
55
56
|
export declare function writingReadmeMetaDataError(error: unknown): string;
|
|
56
57
|
export declare function cantSetupBuiltInTests(error: unknown): string;
|
|
57
58
|
export declare function keepingExistingGitignore(projectName: string): string;
|
|
59
|
+
export declare function keepingExistingMcpConfig(projectName: string): string;
|
|
58
60
|
export declare function existingRepositoryKept(projectName: string): string;
|
package/dist/lib/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const NEVER_SCAFFOLDED_DIRS: string[];
|
|
2
|
-
export declare function copyDirectoryWithSymlinks(source: string, destination: string): Promise<
|
|
3
|
-
export declare function moveDirectoryContents(source: string, destination: string): Promise<
|
|
2
|
+
export declare function copyDirectoryWithSymlinks(source: string, destination: string, root?: string): Promise<string[]>;
|
|
3
|
+
export declare function moveDirectoryContents(source: string, destination: string, root?: string): Promise<string[]>;
|
|
4
4
|
export declare function shellQuote(value: string): string;
|
|
5
5
|
export declare function directoryWriteFailure(directory: string): Promise<NodeJS.ErrnoException | null>;
|
|
6
6
|
export declare function isTypeScriptTemplate(templateName: string): boolean;
|
package/dist/module.cjs
CHANGED
|
@@ -244,7 +244,36 @@ const NEVER_SCAFFOLDED_DIRS = [
|
|
|
244
244
|
'.extension-js',
|
|
245
245
|
'.git'
|
|
246
246
|
];
|
|
247
|
-
async function
|
|
247
|
+
async function linkTargetInside(linkPath, root) {
|
|
248
|
+
let real;
|
|
249
|
+
try {
|
|
250
|
+
real = await promises_namespaceObject.realpath(linkPath);
|
|
251
|
+
} catch {
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
const relative = external_node_path_namespaceObject.relative(root, real);
|
|
255
|
+
if (!relative || relative.startsWith('..') || external_node_path_namespaceObject.isAbsolute(relative)) return null;
|
|
256
|
+
return real;
|
|
257
|
+
}
|
|
258
|
+
function templateRelative(root, file) {
|
|
259
|
+
return external_node_path_namespaceObject.relative(root, file).split(external_node_path_namespaceObject.sep).join('/');
|
|
260
|
+
}
|
|
261
|
+
async function recreateLink(sourcePath, destPath, real) {
|
|
262
|
+
const target = external_node_path_namespaceObject.relative(external_node_path_namespaceObject.dirname(sourcePath), real) || '.';
|
|
263
|
+
const kind = (await promises_namespaceObject.stat(real)).isDirectory() ? 'dir' : 'file';
|
|
264
|
+
try {
|
|
265
|
+
await promises_namespaceObject.symlink(target, destPath, kind);
|
|
266
|
+
} catch (caught) {
|
|
267
|
+
const err = caught;
|
|
268
|
+
if (err?.code === 'EPERM' || err?.code === 'ENOTSUP') await promises_namespaceObject.cp(real, destPath, {
|
|
269
|
+
recursive: true
|
|
270
|
+
});
|
|
271
|
+
else throw err;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
async function copyDirectoryWithSymlinks(source, destination, root) {
|
|
275
|
+
const templateRoot = root ?? await promises_namespaceObject.realpath(source);
|
|
276
|
+
const dropped = [];
|
|
248
277
|
const entries = await promises_namespaceObject.readdir(source, {
|
|
249
278
|
withFileTypes: true
|
|
250
279
|
});
|
|
@@ -256,23 +285,21 @@ async function copyDirectoryWithSymlinks(source, destination) {
|
|
|
256
285
|
const destPath = external_node_path_namespaceObject.join(destination, entry.name);
|
|
257
286
|
if (entry.isDirectory()) {
|
|
258
287
|
if (NEVER_SCAFFOLDED_DIRS.includes(entry.name)) continue;
|
|
259
|
-
await copyDirectoryWithSymlinks(sourcePath, destPath);
|
|
260
|
-
} else if (entry.isSymbolicLink())
|
|
261
|
-
const
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
recursive: true
|
|
269
|
-
});
|
|
270
|
-
} else throw err;
|
|
271
|
-
}
|
|
272
|
-
else await promises_namespaceObject.copyFile(sourcePath, destPath);
|
|
288
|
+
dropped.push(...await copyDirectoryWithSymlinks(sourcePath, destPath, templateRoot));
|
|
289
|
+
} else if (entry.isSymbolicLink()) {
|
|
290
|
+
const real = await linkTargetInside(sourcePath, templateRoot);
|
|
291
|
+
if (!real) {
|
|
292
|
+
dropped.push(templateRelative(templateRoot, sourcePath));
|
|
293
|
+
continue;
|
|
294
|
+
}
|
|
295
|
+
await recreateLink(sourcePath, destPath, real);
|
|
296
|
+
} else await promises_namespaceObject.copyFile(sourcePath, destPath);
|
|
273
297
|
}
|
|
298
|
+
return dropped;
|
|
274
299
|
}
|
|
275
|
-
async function moveDirectoryContents(source, destination) {
|
|
300
|
+
async function moveDirectoryContents(source, destination, root) {
|
|
301
|
+
const templateRoot = root ?? await promises_namespaceObject.realpath(source);
|
|
302
|
+
const dropped = [];
|
|
276
303
|
await promises_namespaceObject.mkdir(destination, {
|
|
277
304
|
recursive: true
|
|
278
305
|
});
|
|
@@ -282,20 +309,15 @@ async function moveDirectoryContents(source, destination) {
|
|
|
282
309
|
for (const entry of entries){
|
|
283
310
|
const sourcePath = external_node_path_namespaceObject.join(source, entry.name);
|
|
284
311
|
const destPath = external_node_path_namespaceObject.join(destination, entry.name);
|
|
285
|
-
if (entry.isDirectory()) await moveDirectoryContents(sourcePath, destPath);
|
|
286
|
-
else if (entry.isSymbolicLink())
|
|
287
|
-
const
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
recursive: true
|
|
295
|
-
});
|
|
296
|
-
} else throw err;
|
|
297
|
-
}
|
|
298
|
-
else try {
|
|
312
|
+
if (entry.isDirectory()) dropped.push(...await moveDirectoryContents(sourcePath, destPath, templateRoot));
|
|
313
|
+
else if (entry.isSymbolicLink()) {
|
|
314
|
+
const real = await linkTargetInside(sourcePath, templateRoot);
|
|
315
|
+
if (!real) {
|
|
316
|
+
dropped.push(templateRelative(templateRoot, sourcePath));
|
|
317
|
+
continue;
|
|
318
|
+
}
|
|
319
|
+
await recreateLink(sourcePath, destPath, real);
|
|
320
|
+
} else try {
|
|
299
321
|
await promises_namespaceObject.rename(sourcePath, destPath);
|
|
300
322
|
} catch (caught) {
|
|
301
323
|
const err = caught;
|
|
@@ -311,6 +333,7 @@ async function moveDirectoryContents(source, destination) {
|
|
|
311
333
|
recursive: true,
|
|
312
334
|
force: true
|
|
313
335
|
});
|
|
336
|
+
return dropped;
|
|
314
337
|
}
|
|
315
338
|
const SHELL_SAFE_PATH = /^[A-Za-z0-9_@%+=:,./-]+$/;
|
|
316
339
|
const SINGLE_QUOTE = String.fromCharCode(39);
|
|
@@ -434,14 +457,14 @@ function templateFetchTimedOut(templateName, ms) {
|
|
|
434
457
|
return `${prefix('error')} Couldn't fetch the template ${external_pintor_default().blue(templateName)} within ${Math.round(ms / 1000)}s.\n${external_pintor_default().red('- Check your network connection.')}\n${external_pintor_default().red('- Set')} ${external_pintor_default().blue('EXTENSION_CREATE_TIMEOUT_MS')} ${external_pintor_default().red('to allow more time.')}`;
|
|
435
458
|
}
|
|
436
459
|
function templateNotFoundInCatalog(templateName, error) {
|
|
437
|
-
return `${prefix('error')} The template ${external_pintor_default().blue(templateName)} is not in the extension-js/
|
|
460
|
+
return `${prefix('error')} The template ${external_pintor_default().blue(templateName)} is not in the extension-js/templates catalog.\n` + (error ? `${fmt.label('REASON')} ${fmt.val(fmt.truncate(String(error)))}\n` : '') + `${external_pintor_default().red('- Run')} ${external_pintor_default().blue('extension create --help')} ${external_pintor_default().red('to list the valid template names.')}\n` + `${external_pintor_default().red('- Pass a GitHub URL to use a template from anywhere.')}`;
|
|
438
461
|
}
|
|
439
462
|
const CAUSE_STACK_LINE = /^\s*at\s/;
|
|
440
463
|
function causeDigest(error) {
|
|
441
464
|
return String(error?.message || error).split(/\r?\n/).map((line)=>line.trim()).filter((line)=>'' !== line && !CAUSE_STACK_LINE.test(line)).join(' ');
|
|
442
465
|
}
|
|
443
466
|
function templatePathNotFound(requested) {
|
|
444
|
-
return `${prefix('error')} Couldn't find the template ${external_pintor_default().blue(requested)}.\n${fmt.label('SEARCHED')} ${fmt.val(`that path on this machine, then the extension-js/
|
|
467
|
+
return `${prefix('error')} Couldn't find the template ${external_pintor_default().blue(requested)}.\n${fmt.label('SEARCHED')} ${fmt.val(`that path on this machine, then the extension-js/templates catalog for ${external_node_path_namespaceObject.basename(requested)}`)}\n${external_pintor_default().red('- Pass the path of a template directory that exists.')}\n${external_pintor_default().red('- Run')} ${external_pintor_default().blue('extension create --help')} ${external_pintor_default().red('to list the valid template names.')}`;
|
|
445
468
|
}
|
|
446
469
|
function templateDirectoryIsDestination(templateDir, projectPath) {
|
|
447
470
|
return `${prefix('error')} Can't scaffold a project inside the template it copies.\n${fmt.label('TEMPLATE')} ${fmt.val(templateDir)}\n${fmt.label('OUTPUT')} ${fmt.val(projectPath)}\n${external_pintor_default().red('Choose an output path outside the template directory.')}`;
|
|
@@ -459,20 +482,24 @@ function templateArchiveEntryOutside(url, entry, override) {
|
|
|
459
482
|
return `${prefix('error')} The ZIP archive at the remote URL contains a path outside its folder, so it was refused. Nothing was written.\n${fmt.label('URL')} ${fmt.val(fmt.truncate(url, 160))}\n${fmt.label('ENTRY')} ${fmt.val(fmt.truncate(entry, 160))}\n` + (override ? `${fmt.label('SET BY')} ${fmt.val('EXTENSION_CREATE_TEMPLATE_URL')}\n${overrideRemedy()}` : `${external_pintor_default().red('Use an archive whose entries all stay inside its folder.')}`);
|
|
460
483
|
}
|
|
461
484
|
function overrideRemedy() {
|
|
462
|
-
return `${external_pintor_default().red('Point')} ${external_pintor_default().blue('EXTENSION_CREATE_TEMPLATE_URL')} ${external_pintor_default().red('at a ZIP of the
|
|
485
|
+
return `${external_pintor_default().red('Point')} ${external_pintor_default().blue('EXTENSION_CREATE_TEMPLATE_URL')} ${external_pintor_default().red('at a ZIP of the templates catalog, or unset it to use the default catalog.')}`;
|
|
463
486
|
}
|
|
464
487
|
function templateOverrideFetchFailed(url, error) {
|
|
465
488
|
return `${prefix('error')} Couldn't fetch the template catalog from ${external_pintor_default().blue('EXTENSION_CREATE_TEMPLATE_URL')}.\n${fmt.label('URL')} ${fmt.val(fmt.truncate(url, 160))}\n${fmt.label('REASON')} ${fmt.val(fmt.truncate(causeDigest(error), 600))}\n` + overrideRemedy();
|
|
466
489
|
}
|
|
467
490
|
function templateDownloadFailed(templateName, error) {
|
|
468
|
-
return `${prefix('error')} Couldn't download the template ${external_pintor_default().blue(templateName)} from ${fmt.val('github.com/extension-js/
|
|
491
|
+
return `${prefix('error')} Couldn't download the template ${external_pintor_default().blue(templateName)} from ${fmt.val('github.com/extension-js/templates')}.\n${fmt.label('REASON')} ${fmt.val(fmt.truncate(String(error?.message || error)))}\n${external_pintor_default().red('- Check your network connection and any GitHub rate limit, then try again.')}\n${external_pintor_default().red('- Set')} ${external_pintor_default().blue('EXTENSION_CREATE_TIMEOUT_MS')} ${external_pintor_default().red('to allow more time.')}`;
|
|
469
492
|
}
|
|
470
493
|
function templateOfflineFallback(requestedTemplate, fallbackTemplate, error) {
|
|
471
|
-
return `${prefix('info')} Couldn't download the template ${external_pintor_default().blue(requestedTemplate)} from ${fmt.val('github.com/extension-js/
|
|
494
|
+
return `${prefix('info')} Couldn't download the template ${external_pintor_default().blue(requestedTemplate)} from ${fmt.val('github.com/extension-js/templates')}, so this scaffold uses the offline ${external_pintor_default().blue(fallbackTemplate)} template instead.\n${fmt.label('REASON')} ${fmt.val(fmt.truncate(String(error?.message || error)))}\n${external_pintor_default().gray('- Reconnect and run')} ${external_pintor_default().blue(`extension create --template ${requestedTemplate}`)} ${external_pintor_default().gray('to scaffold it.')}`;
|
|
472
495
|
}
|
|
473
496
|
function removedStaleTemplateLockfiles(fileNames) {
|
|
474
497
|
return `${prefix('info')} Removed the template ${fileNames.map((name)=>fmt.val(name)).join(', ')}. The first install writes a fresh one.`;
|
|
475
498
|
}
|
|
499
|
+
function droppedTemplateLinks(linkPaths) {
|
|
500
|
+
const noun = 1 === linkPaths.length ? 'link' : 'links';
|
|
501
|
+
return `${prefix('info')} Left out the template ${noun} ${linkPaths.map((name)=>fmt.val(name)).join(', ')}: ${1 === linkPaths.length ? 'it points' : 'they point'} outside the template.`;
|
|
502
|
+
}
|
|
476
503
|
function initializingGitForRepository(projectName) {
|
|
477
504
|
return `${prefix('debug')} create git init name=${projectName}`;
|
|
478
505
|
}
|
|
@@ -587,6 +614,9 @@ function cantSetupBuiltInTests(error) {
|
|
|
587
614
|
function keepingExistingGitignore(projectName) {
|
|
588
615
|
return `${prefix('info')} ${external_pintor_default().blue(projectName)} already has a ${external_pintor_default().blue('.gitignore')}.\nKeeping its rules and adding the template rules it lacks.`;
|
|
589
616
|
}
|
|
617
|
+
function keepingExistingMcpConfig(projectName) {
|
|
618
|
+
return `${prefix('info')} ${external_pintor_default().blue(projectName)} already has a ${external_pintor_default().blue('.mcp.json')}.\nKeeping it as it is. The template file was not written over it.`;
|
|
619
|
+
}
|
|
590
620
|
function existingRepositoryKept(projectName) {
|
|
591
621
|
return `${prefix('info')} ${external_pintor_default().blue(projectName)} is already a git repository with history.\nLeft it uncommitted. Review the scaffold and run ${external_pintor_default().blue('git add -A && git commit')} yourself.`;
|
|
592
622
|
}
|
|
@@ -597,9 +627,10 @@ const allowlist = [
|
|
|
597
627
|
'LICENSE',
|
|
598
628
|
'node_modules'
|
|
599
629
|
];
|
|
600
|
-
const HIDDEN_FILES_TEMPLATES_SHIP =
|
|
601
|
-
'.gitignore'
|
|
602
|
-
|
|
630
|
+
const HIDDEN_FILES_TEMPLATES_SHIP = {
|
|
631
|
+
'.gitignore': keepingExistingGitignore,
|
|
632
|
+
'.mcp.json': keepingExistingMcpConfig
|
|
633
|
+
};
|
|
603
634
|
async function createDirectory(projectPath, projectName, logger) {
|
|
604
635
|
logger.log(startingNewExtension(projectName));
|
|
605
636
|
const directoryPreExisted = (0, external_node_fs_namespaceObject.existsSync)(projectPath);
|
|
@@ -615,7 +646,7 @@ async function createDirectory(projectPath, projectName, logger) {
|
|
|
615
646
|
const conflictMessage = await directoryHasConflicts(projectPath, conflictingFiles);
|
|
616
647
|
throw new Error(conflictMessage);
|
|
617
648
|
}
|
|
618
|
-
for (const hidden of HIDDEN_FILES_TEMPLATES_SHIP)if (currentDir.includes(hidden)) logger.log(
|
|
649
|
+
for (const [hidden, keeping] of Object.entries(HIDDEN_FILES_TEMPLATES_SHIP))if (currentDir.includes(hidden)) logger.log(keeping(projectName));
|
|
619
650
|
} catch (error) {
|
|
620
651
|
if (hasChannelPrefix(String(error?.message ?? error))) throw error;
|
|
621
652
|
throw new Error(createDirectoryError(projectName, error));
|
|
@@ -625,6 +656,25 @@ async function createDirectory(projectPath, projectName, logger) {
|
|
|
625
656
|
};
|
|
626
657
|
}
|
|
627
658
|
const EXTENSION_ENV_TYPES_PACKAGE = 'extension';
|
|
659
|
+
const OWN_CHROME_TYPES = '@types/chrome';
|
|
660
|
+
function listsOwnChromeTypes(projectDir) {
|
|
661
|
+
try {
|
|
662
|
+
const pkg = JSON.parse((0, external_node_fs_namespaceObject.readFileSync)(external_node_path_namespaceObject.join(projectDir, 'package.json'), 'utf8'));
|
|
663
|
+
return Boolean(pkg.dependencies?.[OWN_CHROME_TYPES] || pkg.devDependencies?.[OWN_CHROME_TYPES]);
|
|
664
|
+
} catch {
|
|
665
|
+
return false;
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
function projectBringsOwnChromeTypes(projectDir) {
|
|
669
|
+
if (listsOwnChromeTypes(projectDir)) return true;
|
|
670
|
+
let dir = external_node_path_namespaceObject.resolve(projectDir);
|
|
671
|
+
while(true){
|
|
672
|
+
if ((0, external_node_fs_namespaceObject.existsSync)(external_node_path_namespaceObject.join(dir, 'node_modules', OWN_CHROME_TYPES))) return true;
|
|
673
|
+
const parent = external_node_path_namespaceObject.dirname(dir);
|
|
674
|
+
if (parent === dir) return false;
|
|
675
|
+
dir = parent;
|
|
676
|
+
}
|
|
677
|
+
}
|
|
628
678
|
const STYLE_TYPE = 'Readonly<Record<string, string>>';
|
|
629
679
|
const EXTENSION_ENV_WILDCARD_MODULES = Object.freeze([
|
|
630
680
|
{
|
|
@@ -710,7 +760,7 @@ function renderWildcardModuleDeclarations(modules = EXTENSION_ENV_WILDCARD_MODUL
|
|
|
710
760
|
function renderDefineDeclarations(defineTypes = {}) {
|
|
711
761
|
return Object.entries(defineTypes).filter(([name])=>/^[A-Za-z_$][\w$]*$/.test(name)).map(([name, type])=>`declare const ${name}: ${type}\n`).join('');
|
|
712
762
|
}
|
|
713
|
-
function renderExtensionEnvTypes(typePath = EXTENSION_ENV_TYPES_PACKAGE, defineTypes = {}, { inlineAssetTypes = false } = {}) {
|
|
763
|
+
function renderExtensionEnvTypes(typePath = EXTENSION_ENV_TYPES_PACKAGE, defineTypes = {}, { inlineAssetTypes = false, ownChromeTypes = false } = {}) {
|
|
714
764
|
const defineDeclarations = renderDefineDeclarations(defineTypes);
|
|
715
765
|
const assetDeclarations = inlineAssetTypes ? `\n// Asset and stylesheet imports: the ${typePath} package does not resolve
|
|
716
766
|
// from this project, so the declares it ships are written here instead.
|
|
@@ -721,7 +771,11 @@ ${renderWildcardModuleDeclarations()}` : '';
|
|
|
721
771
|
// If you need additional types, consider creating a new *.d.ts file and
|
|
722
772
|
// referencing it in the "include" array of your tsconfig.json file.
|
|
723
773
|
// See https://www.typescriptlang.org/tsconfig#include for more information.
|
|
724
|
-
|
|
774
|
+
${ownChromeTypes ? `/// <reference types="${typePath}/types/legacy" />
|
|
775
|
+
|
|
776
|
+
// This project installs @types/chrome, so it types the extension APIs.
|
|
777
|
+
// Remove that package to get chrome-types and the native browser namespace.
|
|
778
|
+
/// <reference types="chrome" />` : `/// <reference types="${typePath}/types" />`}
|
|
725
779
|
|
|
726
780
|
// Polyfill types for browser.* APIs
|
|
727
781
|
/// <reference types="${typePath}/types/polyfill" />
|
|
@@ -729,7 +783,9 @@ ${assetDeclarations}${defineDeclarations ? `\n${defineDeclarations}` : ''}`;
|
|
|
729
783
|
}
|
|
730
784
|
async function generateExtensionTypes(projectPath, projectName, logger) {
|
|
731
785
|
const extensionEnvFile = external_node_path_namespaceObject.join(projectPath, 'extension-env.d.ts');
|
|
732
|
-
const fileContent = renderExtensionEnvTypes(
|
|
786
|
+
const fileContent = renderExtensionEnvTypes(void 0, {}, {
|
|
787
|
+
ownChromeTypes: projectBringsOwnChromeTypes(projectPath)
|
|
788
|
+
});
|
|
733
789
|
try {
|
|
734
790
|
await promises_namespaceObject.mkdir(projectPath, {
|
|
735
791
|
recursive: true
|
|
@@ -788,8 +844,8 @@ const NETWORK_TIMEOUT_MS = (()=>{
|
|
|
788
844
|
const raw = parseInt(String(process.env.EXTENSION_CREATE_TIMEOUT_MS || ''), 10);
|
|
789
845
|
return Number.isFinite(raw) && raw > 0 ? raw : 60000;
|
|
790
846
|
})();
|
|
791
|
-
const CODELOAD_BASE = 'https://codeload.github.com/extension-js/
|
|
792
|
-
const DEFAULT_TEMPLATES_REF = '
|
|
847
|
+
const CODELOAD_BASE = 'https://codeload.github.com/extension-js/templates/zip';
|
|
848
|
+
const DEFAULT_TEMPLATES_REF = '55291446965c7289ce77cf887ab7f69424d7d31e';
|
|
793
849
|
const BUNDLED_TEMPLATES = [
|
|
794
850
|
"javascript"
|
|
795
851
|
];
|
|
@@ -1050,17 +1106,18 @@ async function withSuppressedOutput(task) {
|
|
|
1050
1106
|
function bundledTemplateDir(templateName) {
|
|
1051
1107
|
return external_node_path_namespaceObject.join(__dirname, '..', 'templates', templateName);
|
|
1052
1108
|
}
|
|
1053
|
-
async function copyTemplateDirectory(sourceDir, projectPath, logger,
|
|
1054
|
-
await copyDirectoryWithSymlinks(sourceDir, projectPath);
|
|
1055
|
-
|
|
1109
|
+
async function copyTemplateDirectory(sourceDir, projectPath, logger, ownerFiles) {
|
|
1110
|
+
const droppedLinks = await copyDirectoryWithSymlinks(sourceDir, projectPath);
|
|
1111
|
+
if (droppedLinks.length) logger.log(droppedTemplateLinks(droppedLinks));
|
|
1112
|
+
await restoreOwnerHiddenFiles(projectPath, ownerFiles);
|
|
1056
1113
|
await removeTemplateScaffoldingFiles(projectPath);
|
|
1057
1114
|
const dropped = await removeStaleTemplateLockfiles(projectPath);
|
|
1058
1115
|
if (dropped.length) logger.log(removedStaleTemplateLockfiles(dropped));
|
|
1059
1116
|
}
|
|
1060
|
-
async function copyBundledTemplate(templateName, projectPath, logger,
|
|
1117
|
+
async function copyBundledTemplate(templateName, projectPath, logger, ownerFiles = NO_OWNER_FILES) {
|
|
1061
1118
|
const localTemplate = bundledTemplateDir(templateName);
|
|
1062
1119
|
if (!(0, external_node_fs_namespaceObject.existsSync)(localTemplate)) return;
|
|
1063
|
-
await copyTemplateDirectory(localTemplate, projectPath, logger,
|
|
1120
|
+
await copyTemplateDirectory(localTemplate, projectPath, logger, ownerFiles);
|
|
1064
1121
|
return {
|
|
1065
1122
|
template: templateName,
|
|
1066
1123
|
source: 'bundled'
|
|
@@ -1185,6 +1242,40 @@ async function restoreOwnerGitignore(projectPath, ownerContents) {
|
|
|
1185
1242
|
const merged = 0 === added.length ? ownerContents : `${ownerContents.replace(/\n?$/, '\n')}\n# Extension.js template rules\n${added.join('\n')}\n`;
|
|
1186
1243
|
await promises_namespaceObject.writeFile(target, merged);
|
|
1187
1244
|
}
|
|
1245
|
+
async function readOwnerMcpConfig(projectPath) {
|
|
1246
|
+
try {
|
|
1247
|
+
return await promises_namespaceObject.readFile(external_node_path_namespaceObject.join(projectPath, '.mcp.json'));
|
|
1248
|
+
} catch {
|
|
1249
|
+
return null;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
const NO_OWNER_FILES = {
|
|
1253
|
+
gitignore: null,
|
|
1254
|
+
mcpConfig: null
|
|
1255
|
+
};
|
|
1256
|
+
async function readOwnerHiddenFiles(projectPath) {
|
|
1257
|
+
return {
|
|
1258
|
+
gitignore: await readOwnerGitignore(projectPath),
|
|
1259
|
+
mcpConfig: await readOwnerMcpConfig(projectPath)
|
|
1260
|
+
};
|
|
1261
|
+
}
|
|
1262
|
+
async function restoreOwnerHiddenFiles(projectPath, ownerFiles) {
|
|
1263
|
+
await restoreOwnerGitignore(projectPath, ownerFiles.gitignore);
|
|
1264
|
+
if (null !== ownerFiles.mcpConfig) await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(projectPath, '.mcp.json'), ownerFiles.mcpConfig);
|
|
1265
|
+
}
|
|
1266
|
+
async function putBackOwnerHiddenFiles(projectPath, ownerFiles) {
|
|
1267
|
+
const files = [
|
|
1268
|
+
[
|
|
1269
|
+
'.gitignore',
|
|
1270
|
+
ownerFiles.gitignore
|
|
1271
|
+
],
|
|
1272
|
+
[
|
|
1273
|
+
'.mcp.json',
|
|
1274
|
+
ownerFiles.mcpConfig
|
|
1275
|
+
]
|
|
1276
|
+
];
|
|
1277
|
+
for (const [name, contents] of files)if (null !== contents) await promises_namespaceObject.writeFile(external_node_path_namespaceObject.join(projectPath, name), contents).catch(()=>{});
|
|
1278
|
+
}
|
|
1188
1279
|
async function importExternalTemplate(projectPath, projectName, template, logger, options) {
|
|
1189
1280
|
const templateName = external_node_path_namespaceObject.basename(template);
|
|
1190
1281
|
const resolvedTemplate = template;
|
|
@@ -1199,7 +1290,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1199
1290
|
if (dirExistedBeforeImport) try {
|
|
1200
1291
|
preExistingEntries = await promises_namespaceObject.readdir(projectPath);
|
|
1201
1292
|
} catch {}
|
|
1202
|
-
const
|
|
1293
|
+
const ownerFiles = dirExistedBeforeImport ? await readOwnerHiddenFiles(projectPath) : NO_OWNER_FILES;
|
|
1203
1294
|
let tempRoot;
|
|
1204
1295
|
try {
|
|
1205
1296
|
if (isRefusedHttpTemplateUrl(template)) throw new InsecureTemplateUrlError(template);
|
|
@@ -1211,14 +1302,14 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1211
1302
|
recursive: true
|
|
1212
1303
|
});
|
|
1213
1304
|
if (localTemplateDir) {
|
|
1214
|
-
await copyTemplateDirectory(localTemplateDir, projectPath, logger,
|
|
1305
|
+
await copyTemplateDirectory(localTemplateDir, projectPath, logger, ownerFiles);
|
|
1215
1306
|
return {
|
|
1216
1307
|
template: external_node_path_namespaceObject.basename(localTemplateDir),
|
|
1217
1308
|
source: 'local'
|
|
1218
1309
|
};
|
|
1219
1310
|
}
|
|
1220
1311
|
if (!isHttp && !isGithub && BUNDLED_TEMPLATES.includes(resolvedTemplate)) {
|
|
1221
|
-
const provenance = await copyBundledTemplate(resolvedTemplate, projectPath, logger,
|
|
1312
|
+
const provenance = await copyBundledTemplate(resolvedTemplate, projectPath, logger, ownerFiles);
|
|
1222
1313
|
if (provenance) return provenance;
|
|
1223
1314
|
}
|
|
1224
1315
|
tempRoot = await promises_namespaceObject.mkdtemp(external_node_path_namespaceObject.join(external_node_os_namespaceObject.tmpdir(), 'extension-js-create-'));
|
|
@@ -1258,6 +1349,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1258
1349
|
return body;
|
|
1259
1350
|
};
|
|
1260
1351
|
let provenance;
|
|
1352
|
+
let droppedLinks = [];
|
|
1261
1353
|
if (isGithub) {
|
|
1262
1354
|
try {
|
|
1263
1355
|
await runGoGitIt(template, tempPath);
|
|
@@ -1269,7 +1361,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1269
1361
|
});
|
|
1270
1362
|
const preferred = candidates.find((d)=>d.isDirectory() && d.name === templateName);
|
|
1271
1363
|
const srcPath = preferred ? external_node_path_namespaceObject.join(tempPath, templateName) : tempPath;
|
|
1272
|
-
await moveDirectoryContents(srcPath, projectPath);
|
|
1364
|
+
droppedLinks = await moveDirectoryContents(srcPath, projectPath);
|
|
1273
1365
|
provenance = {
|
|
1274
1366
|
template: resolvedTemplateName,
|
|
1275
1367
|
source: template
|
|
@@ -1281,7 +1373,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1281
1373
|
});
|
|
1282
1374
|
await extractZipBufferTo(data, tempPath, template);
|
|
1283
1375
|
const sourcePath = await getZipSourcePath(tempPath, template);
|
|
1284
|
-
await moveDirectoryContents(sourcePath, projectPath);
|
|
1376
|
+
droppedLinks = await moveDirectoryContents(sourcePath, projectPath);
|
|
1285
1377
|
provenance = {
|
|
1286
1378
|
template: resolvedTemplateName,
|
|
1287
1379
|
source: template
|
|
@@ -1296,7 +1388,8 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1296
1388
|
} : {}
|
|
1297
1389
|
};
|
|
1298
1390
|
}
|
|
1299
|
-
|
|
1391
|
+
if (droppedLinks.length) logger.log(droppedTemplateLinks(droppedLinks));
|
|
1392
|
+
await restoreOwnerHiddenFiles(projectPath, ownerFiles);
|
|
1300
1393
|
await removeTemplateScaffoldingFiles(projectPath);
|
|
1301
1394
|
const droppedLockfiles = await removeStaleTemplateLockfiles(projectPath);
|
|
1302
1395
|
if (droppedLockfiles.length) logger.log(removedStaleTemplateLockfiles(droppedLockfiles));
|
|
@@ -1308,7 +1401,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1308
1401
|
await promises_namespaceObject.mkdir(projectPath, {
|
|
1309
1402
|
recursive: true
|
|
1310
1403
|
});
|
|
1311
|
-
const fallback = await copyBundledTemplate(OFFLINE_FALLBACK_TEMPLATE, projectPath, logger,
|
|
1404
|
+
const fallback = await copyBundledTemplate(OFFLINE_FALLBACK_TEMPLATE, projectPath, logger, ownerFiles);
|
|
1312
1405
|
if (fallback) {
|
|
1313
1406
|
logger.log(templateOfflineFallback(resolvedTemplateName, OFFLINE_FALLBACK_TEMPLATE, error));
|
|
1314
1407
|
return fallback;
|
|
@@ -1318,6 +1411,7 @@ async function importExternalTemplate(projectPath, projectName, template, logger
|
|
|
1318
1411
|
const frame = insecureUrl ? templateUrlNotHttps(insecureUrl.url) : error instanceof TemplateNotFoundError ? looksLikeTemplatePath(template) ? templatePathNotFound(template) : templateNotFoundInCatalog(templateName, error.cause) : error instanceof TemplateNotZipError ? templateUrlNotZip(error.url, error.got, catalogOverride) : error instanceof TemplateArchiveEntryOutsideError ? templateArchiveEntryOutside(error.url, error.entry, catalogOverride) : error instanceof TemplateArchiveDamagedError ? templateArchiveDamaged(error.url, error.reason, catalogOverride) : error instanceof TemplateDownloadError ? isHttp ? templateUrlFetchFailed(template, error) : catalogOverride ? templateOverrideFetchFailed(catalogOverride, error) : templateDownloadFailed(templateName, error) : null;
|
|
1319
1412
|
if (null === frame && !hasChannelPrefix(String(error?.message))) logger.error(installingFromTemplateError(templateName, error));
|
|
1320
1413
|
await cleanupFailedImport(projectPath, ownsProjectDir, preExistingEntries);
|
|
1414
|
+
if (!ownsProjectDir) await putBackOwnerHiddenFiles(projectPath, ownerFiles);
|
|
1321
1415
|
if (null !== frame && error instanceof Error) error.message = frame;
|
|
1322
1416
|
throw error;
|
|
1323
1417
|
} finally{
|
|
@@ -2473,7 +2567,7 @@ async function writeReadmeFile(projectPath, projectName, logger, packageManager)
|
|
|
2473
2567
|
const screenshotHref = hasPublicScreenshot ? './public/screenshot.png' : hasRootScreenshot ? './screenshot.png' : null;
|
|
2474
2568
|
const screenshotEmbed = screenshotHref ? `\n\n` : '';
|
|
2475
2569
|
const blockquote = description ? `> ${description}\n\n` : '';
|
|
2476
|
-
const readme = `<a href="https://extension.js.org" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/Powered%20by%20%7C%20Extension.js-
|
|
2570
|
+
const readme = `<a href="https://extension.js.org" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/Powered%20by%20%7C%20Extension.js-0065e6" alt="Powered by Extension.js" align="right" /></a>\n\n# ${projectName}\n\n` + blockquote + `${screenshotEmbed}` + `## Commands\n` + `\n` + `### dev\n` + `\n` + "Run the extension in development mode. Target a browser with `--browser`:\n" + `\n` + "```bash\n" + `${runPrefix} dev\n` + `${runPrefix} dev${argSeparator} --browser=firefox\n` + `${runPrefix} dev${argSeparator} --browser=edge\n` + "```\n" + `\n` + `### build\n` + `\n` + `Build for production. Convenience scripts target each browser:\n` + `\n` + "```bash\n" + `${runPrefix} build # Chromium (default)\n` + `${runPrefix} build:firefox\n` + `${runPrefix} build:edge\n` + "```\n" + `\n` + `### preview\n` + `\n` + `Preview the production build in the browser:\n` + `\n` + "```bash\n" + `${runPrefix} preview\n` + "```\n" + `\n` + `## Learn more\n` + `\n` + `[Extension.js docs](https://extension.js.org).\n`;
|
|
2477
2571
|
try {
|
|
2478
2572
|
if (isDebug()) logger.log(writingReadmeMetaData());
|
|
2479
2573
|
await promises_namespaceObject.mkdir(projectPath, {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const DEFAULT_TEMPLATES_REF = "
|
|
1
|
+
export declare const DEFAULT_TEMPLATES_REF = "55291446965c7289ce77cf887ab7f69424d7d31e";
|
|
2
2
|
export declare const BUNDLED_TEMPLATES: readonly string[];
|
|
3
3
|
export declare const DEFAULT_TEMPLATE_NAME = "typescript";
|
|
4
4
|
export declare const OFFLINE_FALLBACK_TEMPLATE = "javascript";
|
|
@@ -52,6 +52,11 @@ export interface ImportExternalTemplateOptions {
|
|
|
52
52
|
allowOfflineFallback?: boolean;
|
|
53
53
|
}
|
|
54
54
|
export declare function cleanupFailedImport(projectPath: string, ownsProjectDir: boolean, preExistingEntries: string[]): Promise<void>;
|
|
55
|
+
export interface OwnerHiddenFiles {
|
|
56
|
+
gitignore: string | null;
|
|
57
|
+
mcpConfig: Buffer | null;
|
|
58
|
+
}
|
|
59
|
+
export declare function putBackOwnerHiddenFiles(projectPath: string, ownerFiles: OwnerHiddenFiles): Promise<void>;
|
|
55
60
|
export declare function importExternalTemplate(projectPath: string, projectName: string, template: string, logger: {
|
|
56
61
|
log(...args: unknown[]): void;
|
|
57
62
|
error(...args: unknown[]): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
<a href="https://extension.js.org" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/Powered%20by%20%7C%20Extension.js-
|
|
1
|
+
<a href="https://extension.js.org" target="_blank" rel="noopener noreferrer"><img src="https://img.shields.io/badge/Powered%20by%20%7C%20Extension.js-0065e6" alt="Powered by Extension.js" align="right" /></a>
|
|
2
2
|
|
|
3
3
|
# test-template-javascript
|
|
4
4
|
|
|
@@ -3,7 +3,11 @@
|
|
|
3
3
|
// If you need additional types, consider creating a new *.d.ts file and
|
|
4
4
|
// referencing it in the "include" array of your tsconfig.json file.
|
|
5
5
|
// See https://www.typescriptlang.org/tsconfig#include for more information.
|
|
6
|
-
/// <reference types="extension/types" />
|
|
6
|
+
/// <reference types="extension/types/legacy" />
|
|
7
|
+
|
|
8
|
+
// This project installs @types/chrome, so it types the extension APIs.
|
|
9
|
+
// Remove that package to get chrome-types and the native browser namespace.
|
|
10
|
+
/// <reference types="chrome" />
|
|
7
11
|
|
|
8
12
|
// Polyfill types for browser.* APIs
|
|
9
13
|
/// <reference types="extension/types/polyfill" />
|
package/package.json
CHANGED
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"exports": {
|
|
13
13
|
".": {
|
|
14
|
-
"development": "./
|
|
14
|
+
"development": "./module.ts",
|
|
15
15
|
"types": "./dist/module.d.ts",
|
|
16
16
|
"import": "./dist/module.cjs",
|
|
17
17
|
"require": "./dist/module.cjs",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"templates"
|
|
26
26
|
],
|
|
27
27
|
"name": "extension-create",
|
|
28
|
-
"version": "4.1.
|
|
28
|
+
"version": "4.1.40-canary.459.2c1ba7b",
|
|
29
29
|
"description": "The standalone extension creation engine for Extension.js",
|
|
30
30
|
"author": {
|
|
31
31
|
"name": "Cezar Augusto",
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
},
|
|
44
44
|
"scripts": {
|
|
45
45
|
"clean": "rm -rf dist",
|
|
46
|
-
"watch": "rslib build --watch",
|
|
47
|
-
"compile": "rslib build",
|
|
46
|
+
"watch": "node ../../scripts/run-locked.mjs watch \"rslib build --watch\"",
|
|
47
|
+
"compile": "node ../../scripts/run-locked.mjs compile \"rslib build\"",
|
|
48
48
|
"format": "biome format --write .",
|
|
49
49
|
"lint": "biome lint . && eslint .",
|
|
50
50
|
"pretest:create": "pnpm compile",
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
"devDependencies": {
|
|
87
87
|
"@biomejs/biome": "^2.2.4",
|
|
88
88
|
"@changesets/cli": "^3.0.2",
|
|
89
|
-
"@rslib/core": "^1.0.
|
|
89
|
+
"@rslib/core": "^1.0.6",
|
|
90
90
|
"@types/chrome": "^0.1.33",
|
|
91
91
|
"@types/cross-spawn": "^6.0.6",
|
|
92
92
|
"@types/node": "^26",
|
package/templates/README.md
CHANGED