Skip to content

Commit

Permalink
fix: fix missing dependencies on main package
Browse files Browse the repository at this point in the history
  • Loading branch information
Loïc Mangeonjean committed Apr 30, 2024
1 parent 5dee0da commit 0b0e675
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
11 changes: 9 additions & 2 deletions rollup/rollup-metadata-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ interface GroupResult {
interface Options {
stage?: 'generateBundle' | 'writeBundle'
getGroup?: (entryPoint: string, options: OutputOptions) => { name: string, publicName?: string, priority?: number }
handle (this: PluginContext, group: GroupResult, moduleGroupName: Map<string, string | undefined>, options: OutputOptions, bundle: OutputBundle): void | Promise<void>
handle (this: PluginContext, group: GroupResult, moduleGroupName: Map<string, string | undefined>, otherDependencies: Set<string>, options: OutputOptions, bundle: OutputBundle): void | Promise<void>
}

export default ({ handle, getGroup = () => ({ name: 'main' }), stage = 'generateBundle' }: Options): Plugin => ({
Expand Down Expand Up @@ -129,8 +129,15 @@ export default ({ handle, getGroup = () => ({ name: 'main' }), stage = 'generate
}
})

const otherDependencies = new Set(Array.from(moduleExternalDependencies.values()).map(set => Array.from(set)).flat())
for (const group of groupResults) {
for (const directDependency of group.directDependencies) {
otherDependencies.delete(directDependency)
}
}

await Promise.all(groupResults.map(async (group) => {
await handle.call(this, group, moduleGroupName, options, bundle)
await handle.call(this, group, moduleGroupName, otherDependencies, options, bundle)
}))
}
})
7 changes: 4 additions & 3 deletions rollup/rollup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -713,9 +713,10 @@ export default (args: Record<string, string>): rollup.RollupOptions[] => {
priority: 1
}
},
async handle (group, moduleGroupName, options, bundle) {
async handle (group, moduleGroupName, otherDependencies, options, bundle) {
if (group.name === 'main') {
// Generate package.json
const dependencies = new Set([...group.directDependencies, ...otherDependencies])
const packageJson: PackageJson = {
...Object.fromEntries(Object.entries(pkg).filter(([key]) => ['name', 'description', 'version', 'keywords', 'author', 'license', 'repository', 'type'].includes(key))),
private: false,
Expand Down Expand Up @@ -802,8 +803,8 @@ export default (args: Record<string, string>): rollup.RollupOptions[] => {
}
},
dependencies: {
...Object.fromEntries(Object.entries(pkg.dependencies).filter(([key]) => group.directDependencies.has(key))),
...Object.fromEntries(Array.from(group.directDependencies).filter(dep => dep.startsWith('@codingame/monaco-vscode-')).map(dep => [dep, pkg.version]))
...Object.fromEntries(Object.entries(pkg.dependencies).filter(([key]) => dependencies.has(key))),
...Object.fromEntries(Array.from(dependencies).filter(dep => dep.startsWith('@codingame/monaco-vscode-')).map(dep => [dep, pkg.version]))
}
}
this.emitFile({
Expand Down
4 changes: 2 additions & 2 deletions rollup/rollup.default-extensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export default rollup.defineConfig([
}
}),
metadataPlugin({
handle ({ directDependencies }, moduleGroupName, options, bundle) {
handle ({ directDependencies }, moduleGroupName, otherDependencies, options, bundle) {
const entrypoint = Object.values(bundle).filter(v => (v as rollup.OutputChunk).isEntry)[0]!.fileName
const packageJson: PackageJson = {
name: `@codingame/monaco-vscode-${name}-default-extension`,
Expand Down Expand Up @@ -158,7 +158,7 @@ ${extensions.map(name => ` whenReady${pascalCase(name)}()`).join(',\n')}
}
},
metadataPlugin({
handle ({ directDependencies }, moduleGroupName, options, bundle) {
handle ({ directDependencies }, moduleGroupName, otherDependencies, options, bundle) {
const entrypoint = Object.values(bundle).filter(v => (v as rollup.OutputChunk).isEntry)[0]!.fileName
const packageJson: PackageJson = {
name,
Expand Down
4 changes: 2 additions & 2 deletions rollup/rollup.rollup-plugins.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const config: rollup.RollupOptions[] = [{
preferConst: false
}),
metadataPlugin({
handle (_, dependencies) {
handle ({ directDependencies }) {
const packageJson: PackageJson = {
name: `@codingame/monaco-vscode-${path.basename(output)}`,
...Object.fromEntries(Object.entries(pkg).filter(([key]) => ['version', 'keywords', 'author', 'license', 'repository', 'type'].includes(key))),
Expand All @@ -67,7 +67,7 @@ const config: rollup.RollupOptions[] = [{
types: `${path.basename(output)}.d.ts`,
dependencies: {
vscode: `npm:${pkg.name}@^${pkg.version}`,
...Object.fromEntries(Object.entries(pkg.dependencies).filter(([key]) => dependencies.has(key)))
...Object.fromEntries(Object.entries(pkg.dependencies).filter(([key]) => directDependencies.has(key)))
}
}
this.emitFile({
Expand Down
2 changes: 1 addition & 1 deletion rollup/rollup.types.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default rollup.defineConfig((<{input: Record<string, string>, output: str
priority: 1
}
},
async handle ({ name: groupName, exclusiveModules, entrypoints }, moduleGroupName, options, bundle) {
async handle ({ name: groupName, exclusiveModules, entrypoints }, moduleGroupName, otherDependencies, options, bundle) {
if (groupName === 'main') {
return
}
Expand Down

0 comments on commit 0b0e675

Please sign in to comment.