mirror of
https://github.com/sourcegraph/sourcegraph.git
synced 2026-02-06 15:31:48 +00:00
Update jsonc-parser (#37050)
This commit is contained in:
parent
2ed5bfc6a3
commit
20f937d00b
@ -1,5 +1,4 @@
|
||||
import { applyEdits, parse as parseJSONC } from '@sqs/jsonc-parser'
|
||||
import { setProperty } from '@sqs/jsonc-parser/lib/edit'
|
||||
import { applyEdits, modify, parse as parseJSONC } from 'jsonc-parser'
|
||||
import { from, fromEvent, Observable } from 'rxjs'
|
||||
import { distinctUntilChanged, filter, map, startWith } from 'rxjs/operators'
|
||||
|
||||
@ -179,12 +178,12 @@ export async function editClientSettings(edit: SettingsEdit | string): Promise<v
|
||||
? edit
|
||||
: applyEdits(
|
||||
previous,
|
||||
// TODO(chris): remove `.slice()` (which guards against mutation) once
|
||||
// https://github.com/Microsoft/node-jsonc-parser/pull/12 is merged in.
|
||||
setProperty(previous, edit.path.slice(), edit.value, {
|
||||
tabSize: 2,
|
||||
insertSpaces: true,
|
||||
eol: '\n',
|
||||
modify(previous, edit.path, edit.value, {
|
||||
formattingOptions: {
|
||||
tabSize: 2,
|
||||
insertSpaces: true,
|
||||
eol: '\n',
|
||||
},
|
||||
})
|
||||
)
|
||||
if (isInPage) {
|
||||
|
||||
@ -5,9 +5,9 @@ import {
|
||||
FormattingOptions,
|
||||
parse,
|
||||
ParseError,
|
||||
ParseErrorCode,
|
||||
format as jsoncFormat,
|
||||
} from '@sqs/jsonc-parser'
|
||||
printParseErrorCode,
|
||||
} from 'jsonc-parser'
|
||||
|
||||
import { asError, createAggregateError, ErrorLike } from '../errors'
|
||||
|
||||
@ -35,8 +35,10 @@ function parseJSON(input: string): any {
|
||||
throw createAggregateError(
|
||||
errors.map(error => ({
|
||||
...error,
|
||||
code: ParseErrorCode[error.error],
|
||||
message: `parse error (code: ${error.error}, offset: ${error.offset}, length: ${error.length})`,
|
||||
code: error.error,
|
||||
message: `parse error (code: ${error.error}, error: ${printParseErrorCode(error.error)}, offset: ${
|
||||
error.offset
|
||||
}, length: ${error.length})`,
|
||||
}))
|
||||
)
|
||||
}
|
||||
|
||||
@ -35,7 +35,10 @@ const FIXTURE_USER_WITH_SETTINGS_ERROR: SettingsSubject & SubjectSettingsContent
|
||||
latestSettings: { id: 3, contents: '.' },
|
||||
}
|
||||
|
||||
const SETTINGS_ERROR_FOR_FIXTURE_USER = createAggregateError([new Error('parse error (code: 0, offset: 0, length: 1)')])
|
||||
const SETTINGS_ERROR_FOR_FIXTURE_USER = createAggregateError([
|
||||
new Error('parse error (code: 1, error: InvalidSymbol, offset: 0, length: 1)'),
|
||||
new Error('parse error (code: 4, error: ValueExpected, offset: 1, length: 0)'),
|
||||
])
|
||||
|
||||
describe('gqlToCascade', () => {
|
||||
test('converts a value', () => {
|
||||
|
||||
@ -2,11 +2,10 @@ import * as os from 'os'
|
||||
import * as path from 'path'
|
||||
|
||||
import realPercySnapshot from '@percy/puppeteer'
|
||||
import * as jsonc from '@sqs/jsonc-parser'
|
||||
import * as jsoncEdit from '@sqs/jsonc-parser/lib/edit'
|
||||
import delay from 'delay'
|
||||
import expect from 'expect'
|
||||
import getFreePort from 'get-port'
|
||||
import * as jsonc from 'jsonc-parser'
|
||||
import { escapeRegExp } from 'lodash'
|
||||
import { readFile, appendFile, mkdir } from 'mz/fs'
|
||||
import puppeteer, {
|
||||
@ -734,14 +733,17 @@ export function modifyJSONC(
|
||||
text: string,
|
||||
path: jsonc.JSONPath,
|
||||
editFunction: (oldValue: jsonc.Node | undefined) => any
|
||||
): any {
|
||||
const old = jsonc.findNodeAtLocation(jsonc.parseTree(text), path)
|
||||
): string | undefined {
|
||||
const tree = jsonc.parseTree(text)
|
||||
const old = tree ? jsonc.findNodeAtLocation(tree, path) : undefined
|
||||
return jsonc.applyEdits(
|
||||
text,
|
||||
jsoncEdit.setProperty(text, path, editFunction(old), {
|
||||
eol: '\n',
|
||||
insertSpaces: true,
|
||||
tabSize: 2,
|
||||
jsonc.modify(text, path, editFunction(old), {
|
||||
formattingOptions: {
|
||||
eol: '\n',
|
||||
insertSpaces: true,
|
||||
tabSize: 2,
|
||||
},
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
|
||||
import { parse } from '@sqs/jsonc-parser'
|
||||
import { parse } from 'jsonc-parser'
|
||||
|
||||
import { ROOT_PATH, MONACO_EDITOR_PATH } from '@sourcegraph/build-config'
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import fs from 'fs'
|
||||
|
||||
import { parse } from '@sqs/jsonc-parser'
|
||||
import { parse } from 'jsonc-parser'
|
||||
import lodash from 'lodash'
|
||||
|
||||
import { SourcegraphContext } from '../../src/jscontext'
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import React, { useEffect, useState, useCallback } from 'react'
|
||||
|
||||
import { parse as parseJSONC } from '@sqs/jsonc-parser'
|
||||
import * as H from 'history'
|
||||
import { parse as parseJSONC } from 'jsonc-parser'
|
||||
import { catchError } from 'rxjs/operators'
|
||||
|
||||
import { ErrorAlert } from '@sourcegraph/branded/src/components/alerts'
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import React from 'react'
|
||||
|
||||
import { Edit, FormattingOptions, JSONPath } from '@sqs/jsonc-parser'
|
||||
import { setProperty } from '@sqs/jsonc-parser/lib/edit'
|
||||
import { Edit, JSONPath, ModificationOptions, modify } from 'jsonc-parser'
|
||||
import AwsIcon from 'mdi-react/AwsIcon'
|
||||
import BitbucketIcon from 'mdi-react/BitbucketIcon'
|
||||
import GithubIcon from 'mdi-react/GithubIcon'
|
||||
@ -83,10 +82,12 @@ export interface AddExternalServiceOptions {
|
||||
defaultConfig: string
|
||||
}
|
||||
|
||||
const defaultFormattingOptions: FormattingOptions = {
|
||||
eol: '\n',
|
||||
insertSpaces: true,
|
||||
tabSize: 2,
|
||||
const defaultModificationOptions: ModificationOptions = {
|
||||
formattingOptions: {
|
||||
eol: '\n',
|
||||
insertSpaces: true,
|
||||
tabSize: 2,
|
||||
},
|
||||
}
|
||||
|
||||
/**
|
||||
@ -95,7 +96,7 @@ const defaultFormattingOptions: FormattingOptions = {
|
||||
* `"COMMENT_SENTINEL": true` appears in the JSON.
|
||||
*/
|
||||
function editWithComment(config: string, path: JSONPath, value: any, comment: string): Edit {
|
||||
const edit = setProperty(config, path, value, defaultFormattingOptions)[0]
|
||||
const edit = modify(config, path, value, defaultModificationOptions)[0]
|
||||
edit.content = edit.content.replace('"COMMENT_SENTINEL": true', comment)
|
||||
return edit
|
||||
}
|
||||
@ -260,7 +261,7 @@ const githubEditorActions = (isEnterprise: boolean): EditorAction[] => [
|
||||
label: 'Set GitHub URL',
|
||||
run: (config: string) => {
|
||||
const value = 'https://github.example.com'
|
||||
const edits = setProperty(config, ['url'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['url'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -271,7 +272,7 @@ const githubEditorActions = (isEnterprise: boolean): EditorAction[] => [
|
||||
label: 'Set access token',
|
||||
run: (config: string) => {
|
||||
const value = '<access token>'
|
||||
const edits = setProperty(config, ['token'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['token'], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<access token>' }
|
||||
},
|
||||
},
|
||||
@ -280,7 +281,7 @@ const githubEditorActions = (isEnterprise: boolean): EditorAction[] => [
|
||||
label: 'Add repositories in an organization',
|
||||
run: (config: string) => {
|
||||
const value = '<organization name>'
|
||||
const edits = setProperty(config, ['orgs', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['orgs', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<organization name>' }
|
||||
},
|
||||
},
|
||||
@ -289,7 +290,7 @@ const githubEditorActions = (isEnterprise: boolean): EditorAction[] => [
|
||||
label: 'Add repositories matching a search query',
|
||||
run: (config: string) => {
|
||||
const value = '<search query>'
|
||||
const edits = setProperty(config, ['repositoryQuery', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['repositoryQuery', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<search query>' }
|
||||
},
|
||||
},
|
||||
@ -298,7 +299,7 @@ const githubEditorActions = (isEnterprise: boolean): EditorAction[] => [
|
||||
label: 'Add repositories affiliated with token',
|
||||
run: (config: string) => {
|
||||
const value = 'affiliated'
|
||||
const edits = setProperty(config, ['repositoryQuery', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['repositoryQuery', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: 'affiliated' }
|
||||
},
|
||||
},
|
||||
@ -307,7 +308,7 @@ const githubEditorActions = (isEnterprise: boolean): EditorAction[] => [
|
||||
label: 'Add a single repository',
|
||||
run: (config: string) => {
|
||||
const value = '<owner>/<repository>'
|
||||
const edits = setProperty(config, ['repos', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['repos', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<owner>/<repository>' }
|
||||
},
|
||||
},
|
||||
@ -316,7 +317,7 @@ const githubEditorActions = (isEnterprise: boolean): EditorAction[] => [
|
||||
label: 'Exclude a repository',
|
||||
run: (config: string) => {
|
||||
const value = { name: '<owner>/<repository>' }
|
||||
const edits = setProperty(config, ['exclude', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['exclude', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<owner>/<repository>' }
|
||||
},
|
||||
},
|
||||
@ -337,7 +338,7 @@ const githubEditorActions = (isEnterprise: boolean): EditorAction[] => [
|
||||
label: 'Add webhook',
|
||||
run: (config: string) => {
|
||||
const value = { org: '<your_org_on_GitHub>', secret: '<any_secret_string>' }
|
||||
const edits = setProperty(config, ['webhooks', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['webhooks', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<your_org_on_GitHub>' }
|
||||
},
|
||||
},
|
||||
@ -351,7 +352,7 @@ const gitlabEditorActions = (isSelfManaged: boolean): EditorAction[] => [
|
||||
label: 'Set GitLab URL',
|
||||
run: (config: string) => {
|
||||
const value = 'https://gitlab.example.com'
|
||||
const edits = setProperty(config, ['url'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['url'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -362,7 +363,7 @@ const gitlabEditorActions = (isSelfManaged: boolean): EditorAction[] => [
|
||||
label: 'Set access token',
|
||||
run: (config: string) => {
|
||||
const value = '<access token>'
|
||||
const edits = setProperty(config, ['token'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['token'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -371,7 +372,7 @@ const gitlabEditorActions = (isSelfManaged: boolean): EditorAction[] => [
|
||||
label: 'Add projects in a group',
|
||||
run: (config: string) => {
|
||||
const value = 'groups/<my group>/projects'
|
||||
const edits = setProperty(config, ['projectQuery', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['projectQuery', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<my group>' }
|
||||
},
|
||||
},
|
||||
@ -380,7 +381,7 @@ const gitlabEditorActions = (isSelfManaged: boolean): EditorAction[] => [
|
||||
label: "Add projects that have the token's user as member",
|
||||
run: (config: string) => {
|
||||
const value = 'projects?membership=true&archived=no'
|
||||
const edits = setProperty(config, ['projectQuery', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['projectQuery', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -388,7 +389,7 @@ const gitlabEditorActions = (isSelfManaged: boolean): EditorAction[] => [
|
||||
id: 'addProjectsMatchingSearch',
|
||||
label: 'Add projects matching search',
|
||||
run: (config: string) => ({
|
||||
edits: setProperty(config, ['projectQuery', -1], '?search=<search query>', defaultFormattingOptions),
|
||||
edits: modify(config, ['projectQuery', -1], '?search=<search query>', defaultModificationOptions),
|
||||
selectText: '<search query>',
|
||||
}),
|
||||
},
|
||||
@ -397,7 +398,7 @@ const gitlabEditorActions = (isSelfManaged: boolean): EditorAction[] => [
|
||||
label: 'Add single project by name',
|
||||
run: (config: string) => {
|
||||
const value = { name: '<group>/<name>' }
|
||||
const edits = setProperty(config, ['projects', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['projects', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<group>/<name>' }
|
||||
},
|
||||
},
|
||||
@ -406,7 +407,7 @@ const gitlabEditorActions = (isSelfManaged: boolean): EditorAction[] => [
|
||||
label: 'Add single project by ID',
|
||||
run: (config: string) => {
|
||||
const value = { id: 123 }
|
||||
const edits = setProperty(config, ['projects', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['projects', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '123' }
|
||||
},
|
||||
},
|
||||
@ -417,7 +418,7 @@ const gitlabEditorActions = (isSelfManaged: boolean): EditorAction[] => [
|
||||
label: 'Add internal projects',
|
||||
run: (config: string) => {
|
||||
const value = 'projects?visibility=internal'
|
||||
const edits = setProperty(config, ['projectQuery', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['projectQuery', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -426,7 +427,7 @@ const gitlabEditorActions = (isSelfManaged: boolean): EditorAction[] => [
|
||||
label: 'Add private projects',
|
||||
run: (config: string) => {
|
||||
const value = 'projects?visibility=private'
|
||||
const edits = setProperty(config, ['projectQuery', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['projectQuery', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -437,7 +438,7 @@ const gitlabEditorActions = (isSelfManaged: boolean): EditorAction[] => [
|
||||
label: 'Exclude a project',
|
||||
run: (config: string) => {
|
||||
const value = { name: '<group>/<project>' }
|
||||
const edits = setProperty(config, ['exclude', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['exclude', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '"<group>/<project>"' }
|
||||
},
|
||||
},
|
||||
@ -482,7 +483,7 @@ const gitlabEditorActions = (isSelfManaged: boolean): EditorAction[] => [
|
||||
label: 'Set internal or self-signed certificate',
|
||||
run: (config: string) => {
|
||||
const value = '<certificate>'
|
||||
const edits = setProperty(config, ['certificate'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['certificate'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -509,7 +510,7 @@ const gitlabEditorActions = (isSelfManaged: boolean): EditorAction[] => [
|
||||
label: 'Add webhook',
|
||||
run: (config: string) => {
|
||||
const value = { secret: '<any_secret_string>' }
|
||||
const edits = setProperty(config, ['webhooks', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['webhooks', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<any_secret_string>' }
|
||||
},
|
||||
},
|
||||
@ -615,7 +616,7 @@ const AWS_CODE_COMMIT: AddExternalServiceOptions = {
|
||||
label: 'Set access key ID',
|
||||
run: (config: string) => {
|
||||
const value = '<access key id>'
|
||||
const edits = setProperty(config, ['accessKeyID'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['accessKeyID'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -624,7 +625,7 @@ const AWS_CODE_COMMIT: AddExternalServiceOptions = {
|
||||
label: 'Set secret access key',
|
||||
run: (config: string) => {
|
||||
const value = '<secret access key>'
|
||||
const edits = setProperty(config, ['secretAccessKey'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['secretAccessKey'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -633,7 +634,7 @@ const AWS_CODE_COMMIT: AddExternalServiceOptions = {
|
||||
label: 'Set region',
|
||||
run: (config: string) => {
|
||||
const value = '<region>'
|
||||
const edits = setProperty(config, ['region'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['region'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -645,7 +646,7 @@ const AWS_CODE_COMMIT: AddExternalServiceOptions = {
|
||||
username: '<username>',
|
||||
password: '<password>',
|
||||
}
|
||||
const edits = setProperty(config, ['gitCredentials'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['gitCredentials'], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<username>' }
|
||||
},
|
||||
},
|
||||
@ -654,7 +655,7 @@ const AWS_CODE_COMMIT: AddExternalServiceOptions = {
|
||||
label: 'Exclude a repository',
|
||||
run: (config: string) => {
|
||||
const value = { name: '<owner>/<repository>' }
|
||||
const edits = setProperty(config, ['exclude', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['exclude', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<owner>/<repository>' }
|
||||
},
|
||||
},
|
||||
@ -678,7 +679,7 @@ const BITBUCKET_CLOUD: AddExternalServiceOptions = {
|
||||
label: 'Set app password',
|
||||
run: (config: string) => {
|
||||
const value = '<app password>'
|
||||
const edits = setProperty(config, ['appPassword'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['appPassword'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -687,7 +688,7 @@ const BITBUCKET_CLOUD: AddExternalServiceOptions = {
|
||||
label: 'Set username',
|
||||
run: (config: string) => {
|
||||
const value = '<username to which the app password belongs>'
|
||||
const edits = setProperty(config, ['username'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['username'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -696,7 +697,7 @@ const BITBUCKET_CLOUD: AddExternalServiceOptions = {
|
||||
label: 'Add repositories belonging to team',
|
||||
run: (config: string) => {
|
||||
const value = '<team>'
|
||||
const edits = setProperty(config, ['teams', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['teams', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -705,7 +706,7 @@ const BITBUCKET_CLOUD: AddExternalServiceOptions = {
|
||||
label: 'Enable webhooks',
|
||||
run: (config: string) => {
|
||||
const value = '<any_secret_string>'
|
||||
const edits = setProperty(config, ['webhookSecret'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['webhookSecret'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -842,7 +843,7 @@ const BITBUCKET_SERVER: AddExternalServiceOptions = {
|
||||
label: 'Set URL',
|
||||
run: (config: string) => {
|
||||
const value = 'https://bitbucket.example.com'
|
||||
const edits = setProperty(config, ['url'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['url'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -851,7 +852,7 @@ const BITBUCKET_SERVER: AddExternalServiceOptions = {
|
||||
label: 'Set access token',
|
||||
run: (config: string) => {
|
||||
const value = '<access token>'
|
||||
const edits = setProperty(config, ['token'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['token'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -860,7 +861,7 @@ const BITBUCKET_SERVER: AddExternalServiceOptions = {
|
||||
label: 'Set username',
|
||||
run: (config: string) => {
|
||||
const value = '<username that created access token>'
|
||||
const edits = setProperty(config, ['username'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['username'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -869,7 +870,7 @@ const BITBUCKET_SERVER: AddExternalServiceOptions = {
|
||||
label: 'Add repositories in a project',
|
||||
run: (config: string) => {
|
||||
const value = '?projectname=<project>'
|
||||
const edits = setProperty(config, ['repositoryQuery', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['repositoryQuery', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<project>' }
|
||||
},
|
||||
},
|
||||
@ -878,7 +879,7 @@ const BITBUCKET_SERVER: AddExternalServiceOptions = {
|
||||
label: 'Add individual repository',
|
||||
run: (config: string) => {
|
||||
const value = '<project/<repository>'
|
||||
const edits = setProperty(config, ['repos', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['repos', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<project/<repository>' }
|
||||
},
|
||||
},
|
||||
@ -887,7 +888,7 @@ const BITBUCKET_SERVER: AddExternalServiceOptions = {
|
||||
label: 'Exclude a repository',
|
||||
run: (config: string) => {
|
||||
const value = { name: '<project/<repository>' }
|
||||
const edits = setProperty(config, ['exclude', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['exclude', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '{"name": "<project/<repository>"}' }
|
||||
},
|
||||
},
|
||||
@ -896,7 +897,7 @@ const BITBUCKET_SERVER: AddExternalServiceOptions = {
|
||||
label: 'Set internal or self-signed certificate',
|
||||
run: (config: string) => {
|
||||
const value = '<certificate>'
|
||||
const edits = setProperty(config, ['certificate'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['certificate'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -905,7 +906,7 @@ const BITBUCKET_SERVER: AddExternalServiceOptions = {
|
||||
label: 'Enable webhooks',
|
||||
run: (config: string) => {
|
||||
const value = { webhooks: { secret: '<any_secret_string>' } }
|
||||
const edits = setProperty(config, ['plugin'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['plugin'], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<any_secret_string>' }
|
||||
},
|
||||
},
|
||||
@ -974,7 +975,7 @@ const SRC_SERVE_GIT: AddExternalServiceOptions = {
|
||||
label: 'Sourcegraph in Docker and src serve-git running on host',
|
||||
run: (config: string) => {
|
||||
const value = 'http://host.docker.internal:3434'
|
||||
const edits = setProperty(config, ['url'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['url'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -1021,7 +1022,7 @@ const GITOLITE: AddExternalServiceOptions = {
|
||||
label: 'Set host',
|
||||
run: (config: string) => {
|
||||
const value = 'git@gitolite.example.com'
|
||||
const edits = setProperty(config, ['host'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['host'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -1030,7 +1031,7 @@ const GITOLITE: AddExternalServiceOptions = {
|
||||
label: 'Set prefix',
|
||||
run: (config: string) => {
|
||||
const value = 'gitolite.example.com/'
|
||||
const edits = setProperty(config, ['prefix'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['prefix'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -1059,7 +1060,7 @@ const PHABRICATOR_SERVICE: AddExternalServiceOptions = {
|
||||
label: 'Set Phabricator URL',
|
||||
run: (config: string) => {
|
||||
const value = 'https://phabricator.example.com'
|
||||
const edits = setProperty(config, ['url'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['url'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -1068,7 +1069,7 @@ const PHABRICATOR_SERVICE: AddExternalServiceOptions = {
|
||||
label: 'Set Phabricator access token',
|
||||
run: (config: string) => {
|
||||
const value = '<Phabricator access token>'
|
||||
const edits = setProperty(config, ['token'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['token'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -1080,7 +1081,7 @@ const PHABRICATOR_SERVICE: AddExternalServiceOptions = {
|
||||
callsign: '<Phabricator repository callsign>',
|
||||
path: '<Sourcegraph repository full name>',
|
||||
}
|
||||
const edits = setProperty(config, ['repos', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['repos', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<Phabricator repository callsign>' }
|
||||
},
|
||||
},
|
||||
@ -1126,7 +1127,7 @@ const GENERIC_GIT: AddExternalServiceOptions = {
|
||||
label: 'Set Git host URL',
|
||||
run: (config: string) => {
|
||||
const value = 'https://git.example.com'
|
||||
const edits = setProperty(config, ['url'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['url'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -1135,7 +1136,7 @@ const GENERIC_GIT: AddExternalServiceOptions = {
|
||||
label: 'Add a repository',
|
||||
run: (config: string) => {
|
||||
const value = 'path/to/repository'
|
||||
const edits = setProperty(config, ['repos', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['repos', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -1185,7 +1186,7 @@ const PERFORCE: AddExternalServiceOptions = {
|
||||
label: 'Set max changes',
|
||||
run: (config: string) => {
|
||||
const value = 1000
|
||||
const edits = setProperty(config, ['maxChanges'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['maxChanges'], value, defaultModificationOptions)
|
||||
return { edits, selectText: value }
|
||||
},
|
||||
},
|
||||
@ -1194,7 +1195,7 @@ const PERFORCE: AddExternalServiceOptions = {
|
||||
label: 'Enforce permissions',
|
||||
run: (config: string) => {
|
||||
const value = {}
|
||||
const edits = setProperty(config, ['authorization'], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['authorization'], value, defaultModificationOptions)
|
||||
return { edits, selectText: '"authorization": {}' }
|
||||
},
|
||||
},
|
||||
|
||||
@ -1,7 +1,6 @@
|
||||
import React, { useCallback, useEffect, useState } from 'react'
|
||||
|
||||
import * as jsonc from '@sqs/jsonc-parser'
|
||||
import { setProperty } from '@sqs/jsonc-parser/lib/edit'
|
||||
import * as jsonc from 'jsonc-parser'
|
||||
import CheckIcon from 'mdi-react/CheckIcon'
|
||||
import { useHistory } from 'react-router'
|
||||
import { Observable } from 'rxjs'
|
||||
@ -52,10 +51,12 @@ export const REPOSITORIES_REVISIONS_CONFIG_SCHEMA = {
|
||||
},
|
||||
}
|
||||
|
||||
const defaultFormattingOptions: jsonc.FormattingOptions = {
|
||||
eol: '\n',
|
||||
insertSpaces: true,
|
||||
tabSize: 2,
|
||||
const defaultModificationOptions: jsonc.ModificationOptions = {
|
||||
formattingOptions: {
|
||||
eol: '\n',
|
||||
insertSpaces: true,
|
||||
tabSize: 2,
|
||||
},
|
||||
}
|
||||
|
||||
const actions: {
|
||||
@ -68,7 +69,7 @@ const actions: {
|
||||
label: 'Add repository',
|
||||
run: config => {
|
||||
const value = { [REPOSITORY_KEY]: 'github.com/example/repository-name', [REVISIONS_KEY]: ['HEAD'] }
|
||||
const edits = setProperty(config, [-1], value, defaultFormattingOptions)
|
||||
const edits = jsonc.modify(config, [-1], value, defaultModificationOptions)
|
||||
return { edits, selectText: 'github.com/example/repository-name' }
|
||||
},
|
||||
},
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import * as jsonc from '@sqs/jsonc-parser'
|
||||
import * as jsonc from 'jsonc-parser'
|
||||
|
||||
export const REPOSITORY_KEY = 'repository'
|
||||
export const REVISIONS_KEY = 'revisions'
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import { applyEdits, JSONPath } from '@sqs/jsonc-parser'
|
||||
import { setProperty } from '@sqs/jsonc-parser/lib/edit'
|
||||
import { applyEdits, JSONPath, modify } from 'jsonc-parser'
|
||||
import { describe, before, after, test } from 'mocha'
|
||||
|
||||
import * as GQL from '@sourcegraph/shared/src/schema'
|
||||
@ -418,10 +417,12 @@ async function writeSetting(gqlClient: GraphQLClient, path: JSONPath, value: unk
|
||||
const { subjectID, settingsID, contents: oldContents } = await getGlobalSettings(gqlClient)
|
||||
const newContents = applyEdits(
|
||||
oldContents,
|
||||
setProperty(oldContents, path, value, {
|
||||
eol: '\n',
|
||||
insertSpaces: true,
|
||||
tabSize: 2,
|
||||
modify(oldContents, path, value, {
|
||||
formattingOptions: {
|
||||
eol: '\n',
|
||||
insertSpaces: true,
|
||||
tabSize: 2,
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
|
||||
@ -1,5 +1,3 @@
|
||||
// import { applyEdits, parse } from '@sqs/jsonc-parser'
|
||||
// import { setProperty } from '@sqs/jsonc-parser/lib/edit'
|
||||
import delay from 'delay'
|
||||
import expect from 'expect'
|
||||
import { describe, before, beforeEach, after, afterEach, test } from 'mocha'
|
||||
|
||||
@ -1,5 +1,4 @@
|
||||
import * as jsonc from '@sqs/jsonc-parser'
|
||||
import * as jsoncEdit from '@sqs/jsonc-parser/lib/edit'
|
||||
import * as jsonc from 'jsonc-parser'
|
||||
import { first } from 'lodash'
|
||||
import { throwError } from 'rxjs'
|
||||
import { catchError, map } from 'rxjs/operators'
|
||||
@ -138,10 +137,12 @@ export async function createAuthProvider(
|
||||
}
|
||||
const editFns = [
|
||||
(contents: string) =>
|
||||
jsoncEdit.setProperty(contents, ['auth.providers', -1], authProvider, {
|
||||
eol: '\n',
|
||||
insertSpaces: true,
|
||||
tabSize: 2,
|
||||
jsonc.modify(contents, ['auth.providers', -1], authProvider, {
|
||||
formattingOptions: {
|
||||
eol: '\n',
|
||||
insertSpaces: true,
|
||||
tabSize: 2,
|
||||
},
|
||||
}),
|
||||
]
|
||||
const { destroy } = await editSiteConfig(gqlClient, ...editFns)
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
import * as React from 'react'
|
||||
|
||||
import * as jsonc from '@sqs/jsonc-parser'
|
||||
import classNames from 'classnames'
|
||||
import * as jsonc from 'jsonc-parser'
|
||||
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'
|
||||
import { Subject, Subscription } from 'rxjs'
|
||||
import { distinctUntilChanged, distinctUntilKeyChanged, map, startWith } from 'rxjs/operators'
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
import * as React from 'react'
|
||||
|
||||
import * as jsonc from '@sqs/jsonc-parser'
|
||||
import { setProperty } from '@sqs/jsonc-parser/lib/edit'
|
||||
import classNames from 'classnames'
|
||||
import * as H from 'history'
|
||||
import * as jsonc from 'jsonc-parser'
|
||||
import { RouteComponentProps } from 'react-router'
|
||||
import { Subject, Subscription } from 'rxjs'
|
||||
import { delay, mergeMap, retryWhen, tap, timeout } from 'rxjs/operators'
|
||||
@ -25,10 +24,12 @@ import { fetchSite, reloadSite, updateSiteConfiguration } from './backend'
|
||||
|
||||
import styles from './SiteAdminConfigurationPage.module.scss'
|
||||
|
||||
const defaultFormattingOptions: jsonc.FormattingOptions = {
|
||||
eol: '\n',
|
||||
insertSpaces: true,
|
||||
tabSize: 2,
|
||||
const defaultModificationOptions: jsonc.ModificationOptions = {
|
||||
formattingOptions: {
|
||||
eol: '\n',
|
||||
insertSpaces: true,
|
||||
tabSize: 2,
|
||||
},
|
||||
}
|
||||
|
||||
function editWithComments(
|
||||
@ -37,7 +38,7 @@ function editWithComments(
|
||||
value: any,
|
||||
comments: { [key: string]: string }
|
||||
): jsonc.Edit {
|
||||
const edit = setProperty(config, path, value, defaultFormattingOptions)[0]
|
||||
const edit = jsonc.modify(config, path, value, defaultModificationOptions)[0]
|
||||
for (const commentKey of Object.keys(comments)) {
|
||||
edit.content = edit.content.replace(`"${commentKey}": true,`, comments[commentKey])
|
||||
edit.content = edit.content.replace(`"${commentKey}": true`, comments[commentKey])
|
||||
@ -55,7 +56,7 @@ const quickConfigureActions: {
|
||||
label: 'Set external URL',
|
||||
run: config => {
|
||||
const value = '<external URL>'
|
||||
const edits = setProperty(config, ['externalURL'], value, defaultFormattingOptions)
|
||||
const edits = jsonc.modify(config, ['externalURL'], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<external URL>' }
|
||||
},
|
||||
},
|
||||
@ -64,7 +65,7 @@ const quickConfigureActions: {
|
||||
label: 'Set license key',
|
||||
run: config => {
|
||||
const value = '<license key>'
|
||||
const edits = setProperty(config, ['licenseKey'], value, defaultFormattingOptions)
|
||||
const edits = jsonc.modify(config, ['licenseKey'], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<license key>' }
|
||||
},
|
||||
},
|
||||
|
||||
@ -1,4 +1,4 @@
|
||||
import { parse as parseJSONC } from '@sqs/jsonc-parser'
|
||||
import { parse as parseJSONC } from 'jsonc-parser'
|
||||
import { Observable } from 'rxjs'
|
||||
import { map, tap, mapTo } from 'rxjs/operators'
|
||||
|
||||
|
||||
@ -1,17 +1,18 @@
|
||||
import { FormattingOptions } from '@sqs/jsonc-parser'
|
||||
import { setProperty } from '@sqs/jsonc-parser/lib/edit'
|
||||
import { ModificationOptions, modify } from 'jsonc-parser'
|
||||
|
||||
import { ConfigInsertionFunction } from '../settings/MonacoSettingsEditor'
|
||||
|
||||
const defaultFormattingOptions: FormattingOptions = {
|
||||
eol: '\n',
|
||||
insertSpaces: true,
|
||||
tabSize: 2,
|
||||
const defaultModificationOptions: ModificationOptions = {
|
||||
formattingOptions: {
|
||||
eol: '\n',
|
||||
insertSpaces: true,
|
||||
tabSize: 2,
|
||||
},
|
||||
}
|
||||
|
||||
const setSearchContextLines: ConfigInsertionFunction = config => {
|
||||
const DEFAULT = 3 // a reasonable value that will be clearly different from the default 1
|
||||
return { edits: setProperty(config, ['search.contextLines'], DEFAULT, defaultFormattingOptions) }
|
||||
return { edits: modify(config, ['search.contextLines'], DEFAULT, defaultModificationOptions) }
|
||||
}
|
||||
|
||||
const addSearchScopeToSettings: ConfigInsertionFunction = config => {
|
||||
@ -19,7 +20,7 @@ const addSearchScopeToSettings: ConfigInsertionFunction = config => {
|
||||
name: '<name>',
|
||||
value: '<partial query string that will be inserted when the scope is selected>',
|
||||
}
|
||||
const edits = setProperty(config, ['search.scopes', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['search.scopes', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<name>' }
|
||||
}
|
||||
|
||||
@ -28,7 +29,7 @@ const addQuickLinkToSettings: ConfigInsertionFunction = config => {
|
||||
name: '<human-readable name>',
|
||||
url: '<URL>',
|
||||
}
|
||||
const edits = setProperty(config, ['quicklinks', -1], value, defaultFormattingOptions)
|
||||
const edits = modify(config, ['quicklinks', -1], value, defaultModificationOptions)
|
||||
return { edits, selectText: '<name>' }
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import { readFileSync, unlinkSync } from 'fs'
|
||||
|
||||
import { parse as parseJSONC } from '@sqs/jsonc-parser'
|
||||
import { parse as parseJSONC } from 'jsonc-parser'
|
||||
import * as semver from 'semver'
|
||||
|
||||
import { cacheFolder, readLine, getWeekNumber } from './util'
|
||||
|
||||
@ -377,7 +377,6 @@
|
||||
"@sentry/browser": "^6.13.2",
|
||||
"@slimsag/react-shortcuts": "^1.2.1",
|
||||
"@sourcegraph/extension-api-classes": "^1.1.0",
|
||||
"@sqs/jsonc-parser": "^1.0.3",
|
||||
"@stripe/react-stripe-js": "^1.8.0-0",
|
||||
"@stripe/stripe-js": "^1.29.0",
|
||||
"@types/js-base64": "^3.3.1",
|
||||
@ -427,6 +426,7 @@
|
||||
"js-base64": "^3.7.2",
|
||||
"js-cookie": "^2.2.1",
|
||||
"js-yaml": "^4.1.0",
|
||||
"jsonc-parser": "^3.0.0",
|
||||
"linguist-languages": "^7.14.0",
|
||||
"lodash": "^4.17.20",
|
||||
"lru-cache": "^7.8.0",
|
||||
|
||||
10
yarn.lock
10
yarn.lock
@ -4175,11 +4175,6 @@
|
||||
resolved "https://registry.npmjs.org/@sourcegraph/tsconfig/-/tsconfig-4.0.1.tgz#5965ec41771d2ac5b23b6e0d919cee3e70485840"
|
||||
integrity sha512-G/xsejsR84G5dj3kHJ7svKBo9E5tWl96rUHKP94Y2UDtA7BzUhAYbieM+b9ZUpIRt66h3+MlYbG5HK4UI2zDzw==
|
||||
|
||||
"@sqs/jsonc-parser@^1.0.3":
|
||||
version "1.0.3"
|
||||
resolved "https://registry.npmjs.org/@sqs/jsonc-parser/-/jsonc-parser-1.0.3.tgz#178538e4cb32cad15b47a739cabd77408ba18021"
|
||||
integrity sha512-dW/2OZ1z5r2rhYPcISh8GwRz7lUzVh4S4+Dgw8wg4WDdTL8yqXjQX8Ysd8cUGhzKE9/UbbrLdlj7sEwzI8Bbqw==
|
||||
|
||||
"@statoscope/extensions@5.14.1":
|
||||
version "5.14.1"
|
||||
resolved "https://registry.npmjs.org/@statoscope/extensions/-/extensions-5.14.1.tgz#b7c32b39de447da76b9fa2daada61b2f699754e6"
|
||||
@ -16814,6 +16809,11 @@ json5@^2.1.2, json5@^2.1.3:
|
||||
dependencies:
|
||||
minimist "^1.2.5"
|
||||
|
||||
jsonc-parser@^3.0.0:
|
||||
version "3.0.0"
|
||||
resolved "https://registry.npmjs.org/jsonc-parser/-/jsonc-parser-3.0.0.tgz#abdd785701c7e7eaca8a9ec8cf070ca51a745a22"
|
||||
integrity sha512-fQzRfAbIBnR0IQvftw9FJveWiHp72Fg20giDrHz6TdfB12UH/uue0D3hm57UB5KgAVuniLMCaS8P1IMj9NR7cA==
|
||||
|
||||
jsonfile@^2.1.0:
|
||||
version "2.4.0"
|
||||
resolved "https://registry.npmjs.org/jsonfile/-/jsonfile-2.4.0.tgz#3736a2b428b87bbda0cc83b53fa3d633a35c2ae8"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user