Skip to content

Commit 3d94d37

Browse files
committed
Update output path of user extension types
1 parent ddbe468 commit 3d94d37

File tree

5 files changed

+30
-26
lines changed

5 files changed

+30
-26
lines changed

programs/create/lib/utils.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,11 @@ export function isExternalTemplate(templateName: string) {
7373
}
7474

7575
export function isTypeScriptTemplate(templateName: string) {
76-
if (isExternalTemplate(templateName)) {
77-
return false
78-
}
79-
8076
return (
81-
templateName === 'typescript' ||
82-
templateName.startsWith('typescript-') ||
83-
templateName.endsWith('-typescript')
77+
templateName.includes('typescript') ||
78+
templateName.includes('react') ||
79+
templateName.includes('preact') ||
80+
templateName.includes('svelte') ||
81+
templateName.includes('solid')
8482
)
8583
}

programs/create/steps/generate-extension-types.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ export async function generateExtensionTypes(
1616
const extensionEnvFile = path.join(projectPath, 'extension-env.d.ts')
1717
const typePath =
1818
process.env.EXTENSION_ENV === 'development'
19-
? path.resolve(process.cwd(), 'programs/develop/types')
20-
: 'extension-develop/dist/types'
19+
? path.resolve(process.cwd(), 'programs/cli/types')
20+
: 'extension/dist/types'
2121

2222
const fileContent = `\
2323
// Required Extension.js types for TypeScript projects.
24-
// This file auto-generated and should not be excluded.
25-
// If you need extra types, consider creating a new *.d.ts and
26-
// referencing it in the "include" array in your tsconfig.json file.
27-
// See https://www.typescriptlang.org/tsconfig#include for info.
24+
// This file is auto-generated and should not be excluded.
25+
// If you need additional types, consider creating a new *.d.ts file and
26+
// referencing it in the "include" array of your tsconfig.json file.
27+
// See https://www.typescriptlang.org/tsconfig#include for more information.
2828
/// <reference types="${typePath}/index.d.ts" />
2929
3030
// Polyfill types for browser.* APIs.

programs/develop/commands/commands-lib/generate-extension-types.ts

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,22 +9,19 @@ import path from 'path'
99
import fs from 'fs/promises'
1010
import * as messages from './messages'
1111

12-
export default async function generateExtensionTypes(projectDir: string) {
13-
const extensionEnvFile = path.join(projectDir, 'extension-env.d.ts')
14-
const typesFolderPath = path.join(__dirname, 'types')
15-
const relativeTypePath = path.relative(projectDir, typesFolderPath)
16-
12+
export async function generateExtensionTypes(projectPath: string) {
13+
const extensionEnvFile = path.join(projectPath, 'extension-env.d.ts')
1714
const typePath =
1815
process.env.EXTENSION_ENV === 'development'
19-
? relativeTypePath
20-
: `extension-develop/dist/types`
16+
? path.resolve(process.cwd(), 'programs/cli/types')
17+
: 'extension/dist/types'
2118

2219
const fileContent = `\
2320
// Required Extension.js types for TypeScript projects.
2421
// This file is auto-generated and should not be excluded.
25-
// If you need extra types, consider creating a new *.d.ts and
22+
// If you need additional types, consider creating a new *.d.ts file and
2623
// referencing it in the "include" array of your tsconfig.json file.
27-
// See https://www.typescriptlang.org/tsconfig#include for info.
24+
// See https://www.typescriptlang.org/tsconfig#include for more information.
2825
/// <reference types="${typePath}/index.d.ts" />
2926
3027
// Polyfill types for browser.* APIs.
@@ -34,14 +31,23 @@ export default async function generateExtensionTypes(projectDir: string) {
3431
try {
3532
// Check if the file exists
3633
await fs.access(extensionEnvFile)
34+
35+
// Read the file content
36+
const existingContent = await fs.readFile(extensionEnvFile, 'utf8')
37+
38+
// Check if the file contains the "develop/dist/types" string
39+
if (existingContent.includes('develop/dist/types')) {
40+
// Rewrite previous path for versions < 2.0.0. See #162
41+
await fs.writeFile(extensionEnvFile, fileContent)
42+
}
3743
} catch (err) {
3844
// File does not exist, continue to write it
39-
const manifest = require(path.join(projectDir, 'manifest.json'))
45+
const manifest = require(path.join(projectPath, 'manifest.json'))
4046
console.log(messages.writingTypeDefinitions(manifest))
4147
try {
4248
await fs.writeFile(extensionEnvFile, fileContent)
4349
} catch (writeErr) {
44-
console.log(messages.writeTypeDefinitionsError(writeErr))
50+
console.log(messages.writingTypeDefinitionsError(writeErr))
4551
}
4652
}
4753
}

programs/develop/commands/commands-lib/messages.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ export function writingTypeDefinitions(manifest: Manifest) {
240240
)
241241
}
242242

243-
export function writeTypeDefinitionsError(error: any) {
243+
export function writingTypeDefinitionsError(error: any) {
244244
return `${getLoggingPrefix(
245245
'error'
246246
)} Failed to write the extension type definition. ${red(error)}`

programs/develop/commands/dev.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import fs from 'fs'
99
import path from 'path'
1010
import {devServer} from '../webpack/dev-server'
11-
import generateExtensionTypes from './commands-lib/generate-extension-types'
11+
import {generateExtensionTypes} from './commands-lib/generate-extension-types'
1212
import {isUsingTypeScript} from '../webpack/plugin-js-frameworks/js-tools/typescript'
1313
import {getProjectPath} from './commands-lib/get-project-path'
1414
import * as messages from './commands-lib/messages'

0 commit comments

Comments
 (0)