-
Notifications
You must be signed in to change notification settings - Fork 137
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: improve package json typings #955
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,17 @@ import resolve from 'resolve'; | |
import { Node } from 'broccoli-node-api'; | ||
import { V1Config, WriteV1Config } from './v1-config'; | ||
import { WriteV1AppBoot, ReadV1AppBoot } from './v1-appboot'; | ||
import { PackageCache, TemplateCompiler, TemplateCompilerPlugins, AddonMeta, Package } from '@embroider/core'; | ||
import { | ||
PackageCache, | ||
TemplateCompiler, | ||
TemplateCompilerPlugins, | ||
AddonMeta, | ||
Package, | ||
EmberAppInstance, | ||
OutputFileToInputFileMap, | ||
PackageInfo, | ||
AddonInstance, | ||
} from '@embroider/core'; | ||
import { writeJSONSync, ensureDirSync, copySync, readdirSync, pathExistsSync, existsSync } from 'fs-extra'; | ||
import AddToTree from './add-to-tree'; | ||
import DummyPackage, { OwningAddon } from './dummy-package'; | ||
|
@@ -21,32 +31,15 @@ import SynthesizeTemplateOnlyComponents from './synthesize-template-only-compone | |
import { isEmberAutoImportDynamic } from './detect-babel-plugins'; | ||
import prepHtmlbarsAstPluginsForUnwrap from './prepare-htmlbars-ast-plugins'; | ||
import { readFileSync } from 'fs'; | ||
import type { Options as HTMLBarsOptions } from 'ember-cli-htmlbars'; | ||
import semver from 'semver'; | ||
|
||
// This controls and types the interface between our new world and the classic | ||
// v1 app instance. | ||
|
||
type FilePath = string; | ||
type OutputFileToInputFileMap = { [filePath: string]: FilePath[] }; | ||
|
||
interface EmberApp { | ||
env: string; | ||
name: string; | ||
_scriptOutputFiles: OutputFileToInputFileMap; | ||
_styleOutputFiles: OutputFileToInputFileMap; | ||
legacyTestFilesToAppend: FilePath[]; | ||
vendorTestStaticStyles: FilePath[]; | ||
_customTransformsMap: Map<string, any>; | ||
_nodeModules: Map<string, { name: string; path: FilePath }>; | ||
options: any; | ||
tests: boolean; | ||
trees: any; | ||
project: any; | ||
registry: any; | ||
testIndex(): Node; | ||
getLintTests(): Node; | ||
otherAssetPaths: any[]; | ||
} | ||
type EmberCliHTMLBarsAddon = AddonInstance & { | ||
htmlbarsOptions(): HTMLBarsOptions; | ||
}; | ||
|
||
interface Group { | ||
outputFiles: OutputFileToInputFileMap; | ||
|
@@ -58,8 +51,8 @@ export default class V1App { | |
// used to signal that this is a dummy app owned by a particular addon | ||
owningAddon: Package | undefined; | ||
|
||
static create(app: EmberApp, packageCache: PackageCache): V1App { | ||
if (app.project.pkg.keywords && app.project.pkg.keywords.includes('ember-addon')) { | ||
static create(app: EmberAppInstance, packageCache: PackageCache): V1App { | ||
if (app.project.pkg.keywords?.includes('ember-addon')) { | ||
// we are a dummy app, which is unfortunately weird and special | ||
return new V1DummyApp(app, packageCache); | ||
} else { | ||
|
@@ -71,7 +64,7 @@ export default class V1App { | |
private _implicitScripts: string[] = []; | ||
private _implicitStyles: string[] = []; | ||
|
||
protected constructor(protected app: EmberApp, protected packageCache: PackageCache) {} | ||
protected constructor(protected app: EmberAppInstance, protected packageCache: PackageCache) {} | ||
|
||
// always the name from package.json. Not the one that apps may have weirdly | ||
// customized. | ||
|
@@ -436,10 +429,10 @@ export default class V1App { | |
'implicit-test-styles': this.app.vendorTestStaticStyles.map(remapAsset), | ||
'public-assets': mapKeys(this._publicAssets, (_, key) => remapAsset(key)), | ||
}; | ||
let meta = { | ||
let meta: PackageInfo = { | ||
name: '@embroider/synthesized-vendor', | ||
version: '0.0.0', | ||
keywords: 'ember-addon', | ||
keywords: ['ember-addon'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here is fix |
||
'ember-addon': addonMeta, | ||
}; | ||
writeJSONSync(join(outputPath, 'package.json'), meta, { spaces: 2 }); | ||
|
@@ -499,10 +492,10 @@ export default class V1App { | |
addonMeta['public-assets']![`./assets/${file}`] = `/assets/${file}`; | ||
} | ||
} | ||
let meta = { | ||
let meta: PackageInfo = { | ||
name: '@embroider/synthesized-styles', | ||
version: '0.0.0', | ||
keywords: 'ember-addon', | ||
keywords: ['ember-addon'], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here is fix |
||
'ember-addon': addonMeta, | ||
}; | ||
writeJSONSync(join(outputPath, 'package.json'), meta, { spaces: 2 }); | ||
|
@@ -562,15 +555,17 @@ export default class V1App { | |
} | ||
|
||
get htmlbarsPlugins(): TemplateCompilerPlugins { | ||
let addon = this.app.project.addons.find((a: any) => a.name === 'ember-cli-htmlbars'); | ||
let addon = this.app.project.addons.find( | ||
(a: AddonInstance) => a.name === 'ember-cli-htmlbars' | ||
) as unknown as EmberCliHTMLBarsAddon; | ||
let options = addon.htmlbarsOptions(); | ||
if (options.plugins.ast) { | ||
if (options?.plugins?.ast) { | ||
// even if the app was using @embroider/macros, we drop it from the config | ||
// here in favor of our globally-configured one. | ||
options.plugins.ast = options.plugins.ast.filter((p: any) => !isEmbroiderMacrosPlugin(p)); | ||
prepHtmlbarsAstPluginsForUnwrap(this.app.registry); | ||
} | ||
return options.plugins; | ||
return options.plugins ?? {}; | ||
} | ||
|
||
// our own appTree. Not to be confused with the one that combines the app js | ||
|
@@ -747,7 +742,7 @@ function throwIfMissing<T>( | |
} | ||
|
||
class V1DummyApp extends V1App { | ||
constructor(app: EmberApp, packageCache: PackageCache) { | ||
constructor(app: EmberAppInstance, packageCache: PackageCache) { | ||
super(app, packageCache); | ||
this.owningAddon = new OwningAddon(this.app.project.root, packageCache); | ||
this.packageCache.seed(this.owningAddon); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed one more case here, looks like
meta
exists on Package class, not package.json payload