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: support comments in vscode settings #5436

Merged
merged 9 commits into from
Feb 9, 2023
63 changes: 63 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@
"ci-info": "^3.0.0",
"clean-deep": "^3.0.2",
"commander": "^9.2.0",
"comment-json": "^4.2.3",
"concordance": "^5.0.0",
"configstore": "^5.0.0",
"content-type": "^1.0.4",
Expand Down
10 changes: 5 additions & 5 deletions src/recipes/vscode/settings.mjs
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { mkdir, readFile, stat, writeFile } from 'fs/promises'
import { dirname, relative } from 'path'

import CommentJSON from 'comment-json'
Copy link
Contributor

@danez danez Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the types of comment-json, it looks like it does not have a default export: https://github.com/kaelzhang/node-comment-json/blob/master/index.d.ts#L106

could we instead do:

import { assign, parse, stringify } from 'comment-json'

Or does that not work? The lib is written in commonjs, but at a quick glance it should work.

Copy link
Contributor Author

@tinfoil-knight tinfoil-knight Jan 30, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It works. I've updated it.

import unixify from 'unixify'

export const applySettings = (existingSettings, { denoBinary, edgeFunctionsPath, repositoryRoot }) => {
const relativeEdgeFunctionsPath = unixify(relative(repositoryRoot, edgeFunctionsPath))
const settings = {
...existingSettings,
const settings = CommentJSON.assign(existingSettings, {
'deno.enable': true,
'deno.enablePaths': existingSettings['deno.enablePaths'] || [],
'deno.unstable': true,
'deno.importMap': '.netlify/edge-functions-import-map.json',
}
})

// If the Edge Functions path isn't already in `deno.enabledPaths`, let's add
// it.
Expand Down Expand Up @@ -42,7 +42,7 @@ export const getSettings = async (settingsPath) => {

return {
fileExists: true,
settings: JSON.parse(file),
settings: CommentJSON.parse(file.toString()),
}
} catch (error) {
if (error.code !== 'ENOENT') {
Expand All @@ -57,7 +57,7 @@ export const getSettings = async (settingsPath) => {
}

export const writeSettings = async ({ settings, settingsPath }) => {
const serializedSettings = JSON.stringify(settings, null, 2)
const serializedSettings = CommentJSON.stringify(settings, null, 2)

await mkdir(dirname(settingsPath), { recursive: true })
await writeFile(settingsPath, serializedSettings)
Expand Down