extension-create 3.1.0-next.8 → 3.2.0-next.10

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.
@@ -0,0 +1,3 @@
1
+ type PackageManagerName = 'pnpm' | 'yarn' | 'npm';
2
+ export declare function detectPackageManagerFromEnv(): PackageManagerName;
3
+ export {};
@@ -1,8 +1,5 @@
1
- export declare function copyDirectory(source: string, destination: string): Promise<void[]>;
2
1
  export declare function copyDirectoryWithSymlinks(source: string, destination: string): Promise<void>;
3
2
  export declare function moveDirectoryContents(source: string, destination: string): Promise<void>;
4
- export declare function getInstallCommand(): Promise<string>;
5
- export declare function getTemplatePath(workingDir: string): string;
3
+ export declare function getInstallCommand(): Promise<"pnpm" | "yarn" | "npm">;
6
4
  export declare function isDirectoryWriteable(directory: string, projectName: string): Promise<boolean>;
7
- export declare function isExternalTemplate(_templateName: string): boolean;
8
5
  export declare function isTypeScriptTemplate(templateName: string): boolean;
package/dist/module.js CHANGED
@@ -42,7 +42,18 @@ const external_path_namespaceObject = require("path");
42
42
  const external_fs_namespaceObject = require("fs");
43
43
  const external_pintor_namespaceObject = require("pintor");
44
44
  var external_pintor_default = /*#__PURE__*/ __webpack_require__.n(external_pintor_namespaceObject);
45
- const external_package_manager_detector_namespaceObject = require("package-manager-detector");
45
+ function detectPackageManagerFromEnv() {
46
+ const userAgent = process.env.npm_config_user_agent || '';
47
+ if (userAgent.includes('pnpm')) return 'pnpm';
48
+ if (userAgent.includes('yarn')) return 'yarn';
49
+ if (userAgent.includes('npm')) return 'npm';
50
+ const execPath = process.env.npm_execpath || process.env.NPM_EXEC_PATH || '';
51
+ if (execPath.includes('pnpm')) return 'pnpm';
52
+ if (execPath.includes('yarn')) return 'yarn';
53
+ execPath.includes('npm');
54
+ return 'npm';
55
+ }
56
+ const statusPrefix = external_pintor_default().brightBlue('►►►');
46
57
  function destinationNotWriteable(workingDir) {
47
58
  const workingDirFolder = external_path_namespaceObject.basename(workingDir);
48
59
  return `${external_pintor_default().red('Error')} Couldn't write to the destination directory.\n${external_pintor_default().red('Next step: choose a writable path or update folder permissions.')}\n${external_pintor_default().red('Path')} ${external_pintor_default().underline(workingDirFolder)}`;
@@ -65,10 +76,10 @@ function noUrlAllowed() {
65
76
  }
66
77
  async function successfullInstall(projectPath, projectName, depsInstalled) {
67
78
  const relativePath = external_path_namespaceObject.relative(process.cwd(), projectPath);
68
- const pm = await (0, external_package_manager_detector_namespaceObject.detect)();
79
+ const pm = detectPackageManagerFromEnv();
69
80
  let command = 'npm run';
70
81
  let installCmd = 'npm install';
71
- switch(pm?.name){
82
+ switch(pm){
72
83
  case 'yarn':
73
84
  command = 'yarn dev';
74
85
  installCmd = 'yarn';
@@ -81,42 +92,37 @@ async function successfullInstall(projectPath, projectName, depsInstalled) {
81
92
  command = 'npm run dev';
82
93
  installCmd = 'npm install';
83
94
  }
84
- if (process.env.npm_config_user_agent) {
85
- if (process.env.npm_config_user_agent.includes('pnpm')) {
86
- command = 'pnpm dev';
87
- installCmd = 'pnpm install';
88
- }
89
- }
90
95
  const steps = depsInstalled ? ` 1. ${external_pintor_default().blue('cd')} ${external_pintor_default().underline(relativePath)}\n 2. ${external_pintor_default().blue(command)} (runs a fresh browser profile with your extension loaded)\n` : ` 1. ${external_pintor_default().blue('cd')} ${external_pintor_default().underline(relativePath)}\n 2. ${external_pintor_default().blue(installCmd)}\n 3. ${external_pintor_default().blue(command)} (runs a fresh browser profile with your extension loaded)\n`;
91
- return `${external_pintor_default().green('Created')} ${external_pintor_default().blue(projectName)}\n\nNext steps:\n\n` + steps;
96
+ const depsNote = depsInstalled ? `\n${external_pintor_default().gray('Dependencies installed. You can start developing now.')}\n` : '\n';
97
+ return `${statusPrefix} ${external_pintor_default().green('Created')} ${external_pintor_default().blue(projectName)}\n\nNext steps:\n\n` + steps + depsNote;
92
98
  }
93
99
  function startingNewExtension(projectName) {
94
- return `Creating ${external_pintor_default().blue(projectName)}...`;
100
+ return `${statusPrefix} Creating ${external_pintor_default().blue(projectName)}...`;
95
101
  }
96
102
  function checkingIfPathIsWriteable() {
97
- return 'Checking if the destination path is writable...';
103
+ return `${statusPrefix} Checking if the destination path is writable...`;
98
104
  }
99
105
  function scanningPossiblyConflictingFiles() {
100
- return 'Scanning for conflicting files...';
106
+ return `${statusPrefix} Scanning for conflicting files...`;
101
107
  }
102
108
  function createDirectoryError(projectName, error) {
103
109
  return `${external_pintor_default().red('Error')} Couldn't create directory ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: check the path and permissions, then try again.')}`;
104
110
  }
105
111
  function writingTypeDefinitions(projectName) {
106
- return `Writing type definitions for ${external_pintor_default().blue(projectName)}...`;
112
+ return `${statusPrefix} Writing type definitions for ${external_pintor_default().blue(projectName)}...`;
107
113
  }
108
114
  function writingTypeDefinitionsError(error) {
109
115
  return `${external_pintor_default().red('Error')} Couldn't write the extension type definitions.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: check file permissions, then try again.')}`;
110
116
  }
111
117
  function installingFromTemplate(projectName, templateName) {
112
- if ('init' === templateName) return `Installing ${external_pintor_default().blue(projectName)}...`;
113
- return `Installing ${external_pintor_default().blue(projectName)} from template ${external_pintor_default().yellow(templateName)}...`;
118
+ if ('init' === templateName) return `${statusPrefix} Installing ${external_pintor_default().blue(projectName)}...`;
119
+ return `${statusPrefix} Installing ${external_pintor_default().blue(projectName)} from template ${external_pintor_default().yellow(templateName)}...`;
114
120
  }
115
121
  function installingFromTemplateError(projectName, template, error) {
116
122
  return `${external_pintor_default().red('Error')} Couldn't find template ${external_pintor_default().yellow(template)} for ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: choose a valid template name or URL.')}`;
117
123
  }
118
124
  function initializingGitForRepository(projectName) {
119
- return `Initializing git repository for ${external_pintor_default().blue(projectName)}...`;
125
+ return `${statusPrefix} Initializing git repository for ${external_pintor_default().blue(projectName)}...`;
120
126
  }
121
127
  function initializingGitForRepositoryFailed(gitCommand, gitArgs, code) {
122
128
  return `${external_pintor_default().red('Error')} Command ${external_pintor_default().yellow(gitCommand)} ${external_pintor_default().yellow(gitArgs.join(' '))} failed.\n${external_pintor_default().red(`Exit code: ${external_pintor_default().yellow(String(code))}`)}\n${external_pintor_default().red('Next step: run the command manually to inspect the error.')}`;
@@ -128,7 +134,7 @@ function initializingGitForRepositoryError(projectName, error) {
128
134
  return `${external_pintor_default().red('Error')} Couldn't initialize ${external_pintor_default().yellow('git')} for ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error?.message || error))}\n${external_pintor_default().red('Next step: retry initialization or create the repository manually.')}`;
129
135
  }
130
136
  function installingDependencies() {
131
- return 'Installing dependencies (this may take a moment)...';
137
+ return `${statusPrefix} Installing dependencies (this may take a moment)...`;
132
138
  }
133
139
  function installingDependenciesFailed(gitCommand, gitArgs, code) {
134
140
  return `${external_pintor_default().red('Error')} Command ${external_pintor_default().yellow(gitCommand)} ${external_pintor_default().yellow(gitArgs.join(' '))} failed.\n${external_pintor_default().red(`Exit code: ${external_pintor_default().yellow(String(code))}`)}\n${external_pintor_default().red('Next step: run the command manually to inspect the error.')}`;
@@ -140,28 +146,28 @@ function cantInstallDependencies(projectName, error) {
140
146
  return `${external_pintor_default().red('Error')} Couldn't install dependencies for ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error?.message || error))}\n${external_pintor_default().red('Next step: check your package manager settings, then try again.')}`;
141
147
  }
142
148
  function writingPackageJsonMetadata() {
143
- return `Writing ${external_pintor_default().yellow('package.json')}...`;
149
+ return `${statusPrefix} Writing ${external_pintor_default().yellow('package.json')}...`;
144
150
  }
145
151
  function writingPackageJsonMetadataError(projectName, error) {
146
152
  return `${external_pintor_default().red('Error')} Couldn't write ${external_pintor_default().yellow('package.json')} for ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: check file permissions, then try again.')}`;
147
153
  }
148
154
  function writingManifestJsonMetadata() {
149
- return `Writing ${external_pintor_default().yellow('manifest.json')}...`;
155
+ return `${statusPrefix} Writing ${external_pintor_default().yellow('manifest.json')}...`;
150
156
  }
151
157
  function writingManifestJsonMetadataError(projectName, error) {
152
158
  return `${external_pintor_default().red('Error')} Couldn't write ${external_pintor_default().yellow('manifest.json')} for ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: check file permissions, then try again.')}`;
153
159
  }
154
160
  function writingReadmeMetaData() {
155
- return `Writing ${external_pintor_default().yellow('README.md')}...`;
161
+ return `${statusPrefix} Writing ${external_pintor_default().yellow('README.md')}...`;
156
162
  }
157
163
  function writingGitIgnore() {
158
- return `Writing ${external_pintor_default().yellow('.gitignore')}...`;
164
+ return `${statusPrefix} Writing ${external_pintor_default().yellow('.gitignore')}...`;
159
165
  }
160
166
  function writingReadmeMetaDataEError(projectName, error) {
161
167
  return `${external_pintor_default().red('Error')} Couldn't write ${external_pintor_default().yellow('README.md')} for ${external_pintor_default().blue(projectName)}.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: check file permissions, then try again.')}`;
162
168
  }
163
169
  function folderExists(projectName) {
164
- return `Ensuring ${external_pintor_default().blue(projectName)} exists...`;
170
+ return `${statusPrefix} Ensuring ${external_pintor_default().blue(projectName)} exists...`;
165
171
  }
166
172
  function writingDirectoryError(error) {
167
173
  return `${external_pintor_default().red('Error')} Couldn't check directory writability.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: check the path and permissions, then try again.')}`;
@@ -170,9 +176,6 @@ function cantSetupBuiltInTests(projectName, error) {
170
176
  return `${external_pintor_default().red('Error')} Couldn't set up built-in tests for ${external_pintor_default().yellow(projectName)}.\n${external_pintor_default().red(String(error))}\n${external_pintor_default().red('Next step: run the setup step again or skip tests.')}`;
171
177
  }
172
178
  const promises_namespaceObject = require("fs/promises");
173
- const external_url_namespaceObject = require("url");
174
- const utils_filename = (0, external_url_namespaceObject.fileURLToPath)(__rslib_import_meta_url__);
175
- const utils_dirname = external_path_namespaceObject.dirname(utils_filename);
176
179
  async function copyDirectoryWithSymlinks(source, destination) {
177
180
  const entries = await promises_namespaceObject.readdir(source, {
178
181
  withFileTypes: true
@@ -221,26 +224,7 @@ async function moveDirectoryContents(source, destination) {
221
224
  });
222
225
  }
223
226
  async function getInstallCommand() {
224
- const pm = await (0, external_package_manager_detector_namespaceObject.detect)();
225
- let command = 'npm';
226
- if (process.env.npm_config_user_agent) {
227
- if (process.env.npm_config_user_agent.includes('pnpm')) return 'pnpm';
228
- }
229
- switch(pm?.name){
230
- case 'yarn':
231
- command = 'yarn';
232
- break;
233
- case 'pnpm':
234
- command = 'pnpm';
235
- break;
236
- default:
237
- command = 'npm';
238
- }
239
- return command;
240
- }
241
- function getTemplatePath(workingDir) {
242
- const templatesDir = external_path_namespaceObject.resolve(utils_dirname, '..', 'template');
243
- return external_path_namespaceObject.resolve(workingDir, templatesDir);
227
+ return detectPackageManagerFromEnv();
244
228
  }
245
229
  async function isDirectoryWriteable(directory, projectName) {
246
230
  try {
@@ -254,9 +238,6 @@ async function isDirectoryWriteable(directory, projectName) {
254
238
  return false;
255
239
  }
256
240
  }
257
- function isExternalTemplate(_templateName) {
258
- return true;
259
- }
260
241
  function isTypeScriptTemplate(templateName) {
261
242
  return templateName.includes("typescript") || templateName.includes('react') || templateName.includes('preact') || templateName.includes('svelte') || templateName.includes('solid');
262
243
  }
@@ -287,6 +268,7 @@ async function createDirectory(projectPath, projectName) {
287
268
  throw new Error(createDirectoryError(projectName, error));
288
269
  }
289
270
  }
271
+ const external_url_namespaceObject = require("url");
290
272
  const external_os_namespaceObject = require("os");
291
273
  const external_axios_namespaceObject = require("axios");
292
274
  var external_axios_default = /*#__PURE__*/ __webpack_require__.n(external_axios_namespaceObject);
@@ -299,7 +281,10 @@ const import_external_template_dirname = external_path_namespaceObject.dirname(i
299
281
  async function importExternalTemplate(projectPath, projectName, template) {
300
282
  const templateName = external_path_namespaceObject.basename(template);
301
283
  const examplesUrl = 'https://github.com/extension-js/examples/tree/main/examples';
302
- const templateUrl = `${examplesUrl}/${template}`;
284
+ const resolvedTemplate = 'init' === templateName ? "javascript" : template;
285
+ const resolvedTemplateName = 'init' === templateName ? "javascript" : templateName;
286
+ const templateUrl = `${examplesUrl}/${resolvedTemplate}`;
287
+ const examplesZipUrl = 'https://codeload.github.com/extension-js/examples/zip/refs/heads/main';
303
288
  try {
304
289
  await promises_namespaceObject.mkdir(projectPath, {
305
290
  recursive: true
@@ -322,8 +307,7 @@ async function importExternalTemplate(projectPath, projectName, template) {
322
307
  }
323
308
  const localTemplatesRoot = await findTemplatesRoot(import_external_template_dirname);
324
309
  if (!localTemplatesRoot) throw new Error('Local templates directory not found');
325
- const localTemplateName = 'init' === templateName ? "javascript" : templateName;
326
- const localTemplatePath = external_path_namespaceObject.join(localTemplatesRoot, localTemplateName);
310
+ const localTemplatePath = external_path_namespaceObject.join(localTemplatesRoot, resolvedTemplateName);
327
311
  await copyDirectoryWithSymlinks(localTemplatePath, projectPath);
328
312
  } else {
329
313
  const tempRoot = await promises_namespaceObject.mkdtemp(external_path_namespaceObject.join(external_os_namespaceObject.tmpdir(), 'extension-js-create-'));
@@ -376,9 +360,39 @@ async function importExternalTemplate(projectPath, projectName, template) {
376
360
  zip.extractAllTo(tempPath, true);
377
361
  await moveDirectoryContents(tempPath, projectPath);
378
362
  } else {
379
- await withFilteredOutput(()=>external_go_git_it_default()(templateUrl, tempPath, installingFromTemplate(projectName, templateName)));
380
- const srcPath = external_path_namespaceObject.join(tempPath, templateName);
381
- await moveDirectoryContents(srcPath, projectPath);
363
+ const ok = await (async ()=>{
364
+ const zipExtractRoot = external_path_namespaceObject.join(tempPath, 'zip-extract');
365
+ try {
366
+ const { data } = await external_axios_default().get(examplesZipUrl, {
367
+ responseType: 'arraybuffer',
368
+ maxRedirects: 5
369
+ });
370
+ const zip = new (external_adm_zip_default())(Buffer.from(data));
371
+ zip.extractAllTo(zipExtractRoot, true);
372
+ const entries = await promises_namespaceObject.readdir(zipExtractRoot, {
373
+ withFileTypes: true
374
+ });
375
+ const rootDir = entries.find((e)=>e.isDirectory())?.name;
376
+ if (!rootDir) return false;
377
+ const srcPath = external_path_namespaceObject.join(zipExtractRoot, rootDir, 'examples', resolvedTemplateName);
378
+ await moveDirectoryContents(srcPath, projectPath);
379
+ return true;
380
+ } catch {
381
+ return false;
382
+ } finally{
383
+ try {
384
+ await promises_namespaceObject.rm(zipExtractRoot, {
385
+ recursive: true,
386
+ force: true
387
+ });
388
+ } catch {}
389
+ }
390
+ })();
391
+ if (!ok) {
392
+ await withFilteredOutput(()=>external_go_git_it_default()(templateUrl, tempPath, installingFromTemplate(projectName, templateName)));
393
+ const srcPath = external_path_namespaceObject.join(tempPath, resolvedTemplateName);
394
+ await moveDirectoryContents(srcPath, projectPath);
395
+ }
382
396
  }
383
397
  await promises_namespaceObject.rm(tempRoot, {
384
398
  recursive: true,
@@ -397,9 +411,8 @@ const extensionJsPackageJsonScripts = {
397
411
  'build:firefox': 'development' === process.env.EXTENSION_ENV ? 'node node_modules/extension build --browser firefox' : 'extension build --browser firefox',
398
412
  'build:edge': 'development' === process.env.EXTENSION_ENV ? 'node node_modules/extension build --browser edge' : 'extension build --browser edge'
399
413
  };
400
- async function overridePackageJson(projectPath, projectName, { template, cliVersion }) {
401
- const templatePath = getTemplatePath(process.cwd());
402
- const candidatePath = isExternalTemplate(template) ? external_path_namespaceObject.join(projectPath, 'package.json') : external_path_namespaceObject.join(templatePath, 'package.json');
414
+ async function overridePackageJson(projectPath, projectName, { template: _template, cliVersion }) {
415
+ const candidatePath = external_path_namespaceObject.join(projectPath, 'package.json');
403
416
  let packageJson = {};
404
417
  try {
405
418
  const packageJsonContent = await promises_namespaceObject.readFile(candidatePath);
@@ -616,17 +629,137 @@ async function writeManifestJson(projectPath, projectName) {
616
629
  }
617
630
  async function generateExtensionTypes(projectPath, projectName) {
618
631
  const extensionEnvFile = external_path_namespaceObject.join(projectPath, 'extension-env.d.ts');
619
- const typePath = 'extension';
632
+ const { dependencies, devDependencies, peerDependencies, optionalDependencies } = await readPackageJson(projectPath);
633
+ const hasDependency = (name)=>Boolean(dependencies[name] || devDependencies[name] || peerDependencies[name] || optionalDependencies[name]);
634
+ const usesReact = hasDependency('react') || hasDependency('@types/react');
635
+ const usesReactDom = hasDependency('react-dom') || hasDependency('@types/react-dom');
636
+ const usesSvelte = hasDependency('svelte');
637
+ const frameworkTypeRefs = [
638
+ usesReact ? '/// <reference types="react" />' : '',
639
+ usesReactDom ? '/// <reference types="react-dom" />' : '',
640
+ usesSvelte ? '/// <reference types="svelte" />' : ''
641
+ ].filter(Boolean).join('\n');
620
642
  const fileContent = `\
621
643
  // Required Extension.js types for TypeScript projects.
622
644
  // This file is auto-generated and should not be excluded.
623
- // If you need additional types, consider creating a new *.d.ts file and
624
- // referencing it in the "include" array of your tsconfig.json file.
625
- // See https://www.typescriptlang.org/tsconfig#include for more information.
626
- /// <reference types="${typePath}/types" />
645
+ //
646
+ /// <reference types="webextension-polyfill" />
647
+ /// <reference types="node" />
648
+ /// <reference types="chrome" />
649
+ ${frameworkTypeRefs}
650
+
651
+ declare global {
652
+ const browser: typeof import('webextension-polyfill')
653
+
654
+ type ExtensionBrowser =
655
+ | 'chrome'
656
+ | 'edge'
657
+ | 'firefox'
658
+ | 'chromium-based'
659
+ | 'gecko-based'
660
+
661
+ type ExtensionMode = 'development' | 'production'
662
+
663
+ interface ExtensionEnv {
664
+ EXTENSION_BROWSER: ExtensionBrowser
665
+ EXTENSION_MODE: ExtensionMode
666
+ EXTENSION_PUBLIC_BROWSER: ExtensionBrowser
667
+ EXTENSION_PUBLIC_MODE: ExtensionMode
668
+ EXTENSION_PUBLIC_DESCRIPTION_TEXT: string
669
+ EXTENSION_PUBLIC_LLM_API_KEY: string
670
+ EXTENSION_AUTHOR_MODE: string
671
+ EXTENSION_PUBLIC_AUTHOR_MODE: string
672
+ }
673
+
674
+ namespace NodeJS {
675
+ interface ProcessEnv extends ExtensionEnv {
676
+ [key: string]: string | undefined
677
+ }
678
+ }
679
+
680
+ interface ImportMetaEnv extends ExtensionEnv {
681
+ [key: string]: string | undefined
682
+ }
683
+
684
+ interface ImportMeta {
685
+ readonly env: ImportMetaEnv
686
+ readonly webpackHot?: {
687
+ accept: (module?: string | string[], callback?: () => void) => void
688
+ dispose: (callback: () => void) => void
689
+ }
690
+ url: string
691
+ }
692
+
693
+ interface Window {
694
+ /**
695
+ * @deprecated
696
+ * @description
697
+ * This is how Extension.js used to inject the shadow root into the window object.
698
+ * Use the shadowRoot reference from the content script instead.
699
+ */
700
+ __EXTENSION_SHADOW_ROOT__: ShadowRoot
701
+ }
702
+ }
627
703
 
628
- // Polyfill types for browser.* APIs
629
- /// <reference types="${typePath}/types/polyfill" />
704
+ type CSSContentData = Readonly<Record<string, string>>
705
+ type CSSModuleData = Readonly<Record<string, string>>
706
+
707
+ declare module '*.css' {
708
+ const content: CSSContentData
709
+ export default content
710
+ }
711
+
712
+ declare module '*.module.css' {
713
+ const content: CSSModuleData
714
+ export default content
715
+ }
716
+ declare module '*.module.scss' {
717
+ const content: CSSModuleData
718
+ export default content
719
+ }
720
+ declare module '*.module.sass' {
721
+ const content: CSSModuleData
722
+ export default content
723
+ }
724
+
725
+ declare module '*.png' {
726
+ const content: string
727
+ export default content
728
+ }
729
+ declare module '*.jpg' {
730
+ const content: string
731
+ export default content
732
+ }
733
+ declare module '*.jpeg' {
734
+ const content: string
735
+ export default content
736
+ }
737
+ declare module '*.gif' {
738
+ const content: string
739
+ export default content
740
+ }
741
+ declare module '*.webp' {
742
+ const content: string
743
+ export default content
744
+ }
745
+ declare module '*.avif' {
746
+ const content: string
747
+ export default content
748
+ }
749
+ declare module '*.ico' {
750
+ const content: string
751
+ export default content
752
+ }
753
+ declare module '*.bmp' {
754
+ const content: string
755
+ export default content
756
+ }
757
+ declare module '*.svg' {
758
+ const content: any
759
+ export default content
760
+ }
761
+
762
+ export {}
630
763
  `;
631
764
  try {
632
765
  await promises_namespaceObject.mkdir(projectPath, {
@@ -639,6 +772,26 @@ async function generateExtensionTypes(projectPath, projectName) {
639
772
  throw error;
640
773
  }
641
774
  }
775
+ async function readPackageJson(projectPath) {
776
+ const packageJsonPath = external_path_namespaceObject.join(projectPath, 'package.json');
777
+ try {
778
+ const content = await promises_namespaceObject.readFile(packageJsonPath, 'utf8');
779
+ const parsed = JSON.parse(content) || {};
780
+ return {
781
+ dependencies: parsed.dependencies || {},
782
+ devDependencies: parsed.devDependencies || {},
783
+ peerDependencies: parsed.peerDependencies || {},
784
+ optionalDependencies: parsed.optionalDependencies || {}
785
+ };
786
+ } catch {
787
+ return {
788
+ dependencies: {},
789
+ devDependencies: {},
790
+ peerDependencies: {},
791
+ optionalDependencies: {}
792
+ };
793
+ }
794
+ }
642
795
  const globalDependencies = [
643
796
  '',
644
797
  '# dependencies',
@@ -741,6 +894,15 @@ async function setupBuiltInTests(projectPath, projectName) {
741
894
  throw error;
742
895
  }
743
896
  }
897
+ const external_module_namespaceObject = require("module");
898
+ async function preflightOptionalDependenciesForCreate(projectPath) {
899
+ try {
900
+ const requireFromProject = (0, external_module_namespaceObject.createRequire)(external_path_namespaceObject.join(projectPath, 'package.json'));
901
+ const develop = requireFromProject('extension-develop');
902
+ const preflight = develop?.preflightOptionalDependenciesForProject;
903
+ if ('function' == typeof preflight) await preflight(projectPath, 'development');
904
+ } catch {}
905
+ }
744
906
  async function extensionCreate(projectNameInput, { cliVersion, template = 'init', install = false }) {
745
907
  if (!projectNameInput) throw new Error(noProjectName());
746
908
  if (projectNameInput.startsWith('http')) throw new Error(noUrlAllowed());
@@ -753,7 +915,10 @@ async function extensionCreate(projectNameInput, { cliVersion, template = 'init'
753
915
  template,
754
916
  cliVersion
755
917
  });
756
- if (install) await installDependencies(projectPath, projectName);
918
+ if (install) {
919
+ await installDependencies(projectPath, projectName);
920
+ await preflightOptionalDependenciesForCreate(projectPath);
921
+ }
757
922
  await writeReadmeFile(projectPath, projectName);
758
923
  await writeManifestJson(projectPath, projectName);
759
924
  await initializeGitRepository(projectPath, projectName);
@@ -0,0 +1 @@
1
+ export declare function preflightOptionalDependenciesForCreate(projectPath: string): Promise<void>;
@@ -2,5 +2,5 @@ interface OverridePackageJsonOptions {
2
2
  template: string;
3
3
  cliVersion?: string;
4
4
  }
5
- export declare function overridePackageJson(projectPath: string, projectName: string, { template, cliVersion }: OverridePackageJsonOptions): Promise<void>;
5
+ export declare function overridePackageJson(projectPath: string, projectName: string, { template: _template, cliVersion }: OverridePackageJsonOptions): Promise<void>;
6
6
  export {};
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "name": "extension-create",
25
- "version": "3.1.0-next.8",
25
+ "version": "3.2.0-next.10",
26
26
  "description": "The standalone extension creation engine for Extension.js",
27
27
  "author": {
28
28
  "name": "Cezar Augusto",
@@ -71,7 +71,6 @@
71
71
  "axios": "^1.13.2",
72
72
  "cross-spawn": "^7.0.6",
73
73
  "go-git-it": "^5.0.3",
74
- "package-manager-detector": "^1.6.0",
75
74
  "pintor": "0.3.0",
76
75
  "tiny-glob": "^0.2.9"
77
76
  },
@@ -1,26 +0,0 @@
1
- declare namespace NodeJS {
2
- interface ProcessEnv {
3
- EXTENSION_BROWSER: 'chrome' | 'edge' | 'firefox' | 'chromium-based' | 'gecko-based';
4
- EXTENSION_MODE: 'development' | 'production';
5
- EXTENSION_PUBLIC_BROWSER: 'chrome' | 'edge' | 'firefox' | 'chromium-based' | 'gecko-based';
6
- EXTENSION_PUBLIC_MODE: 'development' | 'production';
7
- EXTENSION_PUBLIC_DESCRIPTION_TEXT: string;
8
- EXTENSION_PUBLIC_LLM_API_KEY: string;
9
- EXTENSION_ENV: 'development' | 'production';
10
- }
11
- }
12
- interface ImportMetaEnv {
13
- EXTENSION_BROWSER: NodeJS.ProcessEnv['EXTENSION_BROWSER'];
14
- EXTENSION_MODE: NodeJS.ProcessEnv['EXTENSION_MODE'];
15
- EXTENSION_PUBLIC_BROWSER: NodeJS.ProcessEnv['EXTENSION_BROWSER'];
16
- EXTENSION_PUBLIC_MODE: NodeJS.ProcessEnv['EXTENSION_MODE'];
17
- [key: string]: string | undefined;
18
- }
19
- interface ImportMeta {
20
- readonly env: ImportMetaEnv;
21
- readonly webpackHot?: {
22
- accept: (module?: string | string[], callback?: () => void) => void;
23
- dispose: (callback: () => void) => void;
24
- };
25
- url: string;
26
- }
@@ -1 +0,0 @@
1
- export declare function importLocalTemplate(projectPath: string, projectName: string, template: string): Promise<void>;