Skip to content
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

feat: don't touch dart.runPubGetOnPubspecChanges when usePubspecOverrides is enabled #38

Merged
merged 1 commit into from
Sep 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/settings.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as vscode from 'vscode'
import { error, info } from './logging'
import { melosWorkspaces } from './melos-workspace'
import { loadMelosWorkspaceConfig } from './workspace-config'

/**
* Ensure that Melos workspaces have default VS Code settings.
Expand All @@ -9,14 +10,16 @@ export async function registerDefaultMelosWorkspaceSettings(
context: vscode.ExtensionContext
) {
await Promise.all(
melosWorkspaces.workspaceFolders.map(applyDefaultMelosWorkspaceSettings)
melosWorkspaces.workspaceFolders.map((folder) =>
applyDefaultMelosWorkspaceSettings(context, folder)
)
)

context.subscriptions.push(
melosWorkspaces.onDidChangeWorkspaceFolders(async (event) => {
for (const folder of event.added) {
try {
await applyDefaultMelosWorkspaceSettings(folder)
await applyDefaultMelosWorkspaceSettings(context, folder)
} catch (e) {
error(
`Failed to apply default Melos workspace settings in '${folder.name}' folder`,
Expand All @@ -31,13 +34,27 @@ export async function registerDefaultMelosWorkspaceSettings(
/**
* The default VS Code settings to apply to a Melos workspace.
*/
const melosWorkspaceDefaultSettings = {
'dart.runPubGetOnPubspecChanges': false,
const melosWorkspaceDefaultSettings: {
'dart.runPubGetOnPubspecChanges'?: string
} = {
'dart.runPubGetOnPubspecChanges': 'never',
}

async function applyDefaultMelosWorkspaceSettings(
context: vscode.ExtensionContext,
folder: vscode.WorkspaceFolder
) {
const defaultSettings = { ...melosWorkspaceDefaultSettings }

const melosConfig = await loadMelosWorkspaceConfig(context, folder)
if (melosConfig?.command?.bootstrap?.usePubspecOverrides === true) {
delete defaultSettings['dart.runPubGetOnPubspecChanges']
}

if (Object.keys(defaultSettings).length === 0) {
return
}

const settings = vscode.workspace.getConfiguration(undefined, folder)

for (const [key, value] of Object.entries(melosWorkspaceDefaultSettings)) {
Expand Down
2 changes: 1 addition & 1 deletion src/test/default-settings/default-settings.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ suite('Default settings', () => {
await openMelosYamlInEditor()

const melosWorkspaceDefaultSettings = {
'dart.runPubGetOnPubspecChanges': false,
'dart.runPubGetOnPubspecChanges': 'never',
}

// Check that all default settings have the correct values.
Expand Down
27 changes: 27 additions & 0 deletions src/workspace-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,38 @@ export interface MelosWorkspaceConfig {
* The YAML document from which the configuration was parsed.
*/
readonly yamlDoc: Document

/**
* Configuration for Melos commands.
*/
readonly command?: MelosCommandsConfig

/**
* The configured Melos scripts.
*/
readonly scripts: readonly MelosScriptConfig[]
}

/**
* Configuration for Melos commands.
*/
export interface MelosCommandsConfig {
/**
* Configuration for the `melos bootstrap` command.
*/
readonly bootstrap: MelosBootstrapConfig
}

/**
* Configuration for the `melos bootstrap` command.
*/
export interface MelosBootstrapConfig {
/**
* Whether Melos should use `pubspec_overrides.yaml` files to override dependencies.
*/
readonly usePubspecOverrides?: boolean
}

/**
* Configuration for a Melos script.
*/
Expand Down Expand Up @@ -158,6 +184,7 @@ function showInvalidMelosYamlMessage(folder: vscode.WorkspaceFolder) {
function melosWorkspaceConfigFromYamlDoc(doc: Document): MelosWorkspaceConfig {
return {
yamlDoc: doc,
command: doc.toJSON()['command'],
scripts: melosScriptsConfigsFromYaml(doc.get('scripts')),
}
}
Expand Down