diff --git a/programs/create/lib/utils.ts b/programs/create/lib/utils.ts
index cb8363c8..bc76e7eb 100644
--- a/programs/create/lib/utils.ts
+++ b/programs/create/lib/utils.ts
@@ -73,13 +73,11 @@ export function isExternalTemplate(templateName: string) {
}
export function isTypeScriptTemplate(templateName: string) {
- if (isExternalTemplate(templateName)) {
- return false
- }
-
return (
- templateName === 'typescript' ||
- templateName.startsWith('typescript-') ||
- templateName.endsWith('-typescript')
+ templateName.includes('typescript') ||
+ templateName.includes('react') ||
+ templateName.includes('preact') ||
+ templateName.includes('svelte') ||
+ templateName.includes('solid')
)
}
diff --git a/programs/create/steps/generate-extension-types.ts b/programs/create/steps/generate-extension-types.ts
index 49fb80f3..3c56e20e 100644
--- a/programs/create/steps/generate-extension-types.ts
+++ b/programs/create/steps/generate-extension-types.ts
@@ -16,15 +16,15 @@ export async function generateExtensionTypes(
const extensionEnvFile = path.join(projectPath, 'extension-env.d.ts')
const typePath =
process.env.EXTENSION_ENV === 'development'
- ? path.resolve(process.cwd(), 'programs/develop/types')
- : 'extension-develop/dist/types'
+ ? path.resolve(process.cwd(), 'programs/cli/types')
+ : 'extension/dist/types'
const fileContent = `\
// Required Extension.js types for TypeScript projects.
-// This file auto-generated and should not be excluded.
-// If you need extra types, consider creating a new *.d.ts and
-// referencing it in the "include" array in your tsconfig.json file.
-// See https://www.typescriptlang.org/tsconfig#include for info.
+// This file is auto-generated and should not be excluded.
+// If you need additional types, consider creating a new *.d.ts file and
+// referencing it in the "include" array of your tsconfig.json file.
+// See https://www.typescriptlang.org/tsconfig#include for more information.
///
// Polyfill types for browser.* APIs.
diff --git a/programs/develop/commands/commands-lib/generate-extension-types.ts b/programs/develop/commands/commands-lib/generate-extension-types.ts
index e25a0909..4ac3946a 100644
--- a/programs/develop/commands/commands-lib/generate-extension-types.ts
+++ b/programs/develop/commands/commands-lib/generate-extension-types.ts
@@ -9,22 +9,19 @@ import path from 'path'
import fs from 'fs/promises'
import * as messages from './messages'
-export default async function generateExtensionTypes(projectDir: string) {
- const extensionEnvFile = path.join(projectDir, 'extension-env.d.ts')
- const typesFolderPath = path.join(__dirname, 'types')
- const relativeTypePath = path.relative(projectDir, typesFolderPath)
-
+export async function generateExtensionTypes(projectPath: string) {
+ const extensionEnvFile = path.join(projectPath, 'extension-env.d.ts')
const typePath =
process.env.EXTENSION_ENV === 'development'
- ? relativeTypePath
- : `extension-develop/dist/types`
+ ? path.resolve(process.cwd(), 'programs/cli/types')
+ : 'extension/dist/types'
const fileContent = `\
// Required Extension.js types for TypeScript projects.
// This file is auto-generated and should not be excluded.
-// If you need extra types, consider creating a new *.d.ts and
+// If you need additional types, consider creating a new *.d.ts file and
// referencing it in the "include" array of your tsconfig.json file.
-// See https://www.typescriptlang.org/tsconfig#include for info.
+// See https://www.typescriptlang.org/tsconfig#include for more information.
///
// Polyfill types for browser.* APIs.
@@ -34,14 +31,23 @@ export default async function generateExtensionTypes(projectDir: string) {
try {
// Check if the file exists
await fs.access(extensionEnvFile)
+
+ // Read the file content
+ const existingContent = await fs.readFile(extensionEnvFile, 'utf8')
+
+ // Check if the file contains the "develop/dist/types" string
+ if (existingContent.includes('develop/dist/types')) {
+ // Rewrite previous path for versions < 2.0.0. See #162
+ await fs.writeFile(extensionEnvFile, fileContent)
+ }
} catch (err) {
// File does not exist, continue to write it
- const manifest = require(path.join(projectDir, 'manifest.json'))
+ const manifest = require(path.join(projectPath, 'manifest.json'))
console.log(messages.writingTypeDefinitions(manifest))
try {
await fs.writeFile(extensionEnvFile, fileContent)
} catch (writeErr) {
- console.log(messages.writeTypeDefinitionsError(writeErr))
+ console.log(messages.writingTypeDefinitionsError(writeErr))
}
}
}
diff --git a/programs/develop/commands/commands-lib/messages.ts b/programs/develop/commands/commands-lib/messages.ts
index 741bc008..8e6d9409 100644
--- a/programs/develop/commands/commands-lib/messages.ts
+++ b/programs/develop/commands/commands-lib/messages.ts
@@ -240,7 +240,7 @@ export function writingTypeDefinitions(manifest: Manifest) {
)
}
-export function writeTypeDefinitionsError(error: any) {
+export function writingTypeDefinitionsError(error: any) {
return `${getLoggingPrefix(
'error'
)} Failed to write the extension type definition. ${red(error)}`
diff --git a/programs/develop/commands/dev.ts b/programs/develop/commands/dev.ts
index 56305c60..92eb784a 100644
--- a/programs/develop/commands/dev.ts
+++ b/programs/develop/commands/dev.ts
@@ -8,7 +8,7 @@
import fs from 'fs'
import path from 'path'
import {devServer} from '../webpack/dev-server'
-import generateExtensionTypes from './commands-lib/generate-extension-types'
+import {generateExtensionTypes} from './commands-lib/generate-extension-types'
import {isUsingTypeScript} from '../webpack/plugin-js-frameworks/js-tools/typescript'
import {getProjectPath} from './commands-lib/get-project-path'
import * as messages from './commands-lib/messages'