extension-create 3.2.0-next.8 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/dist/module.js +185 -13
  2. package/package.json +1 -1
package/dist/module.js CHANGED
@@ -281,7 +281,10 @@ const import_external_template_dirname = external_path_namespaceObject.dirname(i
281
281
  async function importExternalTemplate(projectPath, projectName, template) {
282
282
  const templateName = external_path_namespaceObject.basename(template);
283
283
  const examplesUrl = 'https://github.com/extension-js/examples/tree/main/examples';
284
- 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';
285
288
  try {
286
289
  await promises_namespaceObject.mkdir(projectPath, {
287
290
  recursive: true
@@ -304,8 +307,7 @@ async function importExternalTemplate(projectPath, projectName, template) {
304
307
  }
305
308
  const localTemplatesRoot = await findTemplatesRoot(import_external_template_dirname);
306
309
  if (!localTemplatesRoot) throw new Error('Local templates directory not found');
307
- const localTemplateName = 'init' === templateName ? "javascript" : templateName;
308
- const localTemplatePath = external_path_namespaceObject.join(localTemplatesRoot, localTemplateName);
310
+ const localTemplatePath = external_path_namespaceObject.join(localTemplatesRoot, resolvedTemplateName);
309
311
  await copyDirectoryWithSymlinks(localTemplatePath, projectPath);
310
312
  } else {
311
313
  const tempRoot = await promises_namespaceObject.mkdtemp(external_path_namespaceObject.join(external_os_namespaceObject.tmpdir(), 'extension-js-create-'));
@@ -358,9 +360,39 @@ async function importExternalTemplate(projectPath, projectName, template) {
358
360
  zip.extractAllTo(tempPath, true);
359
361
  await moveDirectoryContents(tempPath, projectPath);
360
362
  } else {
361
- await withFilteredOutput(()=>external_go_git_it_default()(templateUrl, tempPath, installingFromTemplate(projectName, templateName)));
362
- const srcPath = external_path_namespaceObject.join(tempPath, templateName);
363
- 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
+ }
364
396
  }
365
397
  await promises_namespaceObject.rm(tempRoot, {
366
398
  recursive: true,
@@ -597,17 +629,137 @@ async function writeManifestJson(projectPath, projectName) {
597
629
  }
598
630
  async function generateExtensionTypes(projectPath, projectName) {
599
631
  const extensionEnvFile = external_path_namespaceObject.join(projectPath, 'extension-env.d.ts');
600
- 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');
601
642
  const fileContent = `\
602
643
  // Required Extension.js types for TypeScript projects.
603
644
  // This file is auto-generated and should not be excluded.
604
- // If you need additional types, consider creating a new *.d.ts file and
605
- // referencing it in the "include" array of your tsconfig.json file.
606
- // See https://www.typescriptlang.org/tsconfig#include for more information.
607
- /// <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
+ }
703
+
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
+ }
608
724
 
609
- // Polyfill types for browser.* APIs
610
- /// <reference types="${typePath}/types/polyfill" />
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 {}
611
763
  `;
612
764
  try {
613
765
  await promises_namespaceObject.mkdir(projectPath, {
@@ -620,6 +772,26 @@ async function generateExtensionTypes(projectPath, projectName) {
620
772
  throw error;
621
773
  }
622
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
+ }
623
795
  const globalDependencies = [
624
796
  '',
625
797
  '# dependencies',
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "dist"
23
23
  ],
24
24
  "name": "extension-create",
25
- "version": "3.2.0-next.8",
25
+ "version": "3.2.0",
26
26
  "description": "The standalone extension creation engine for Extension.js",
27
27
  "author": {
28
28
  "name": "Cezar Augusto",