Skip to content

Commit

Permalink
Update npm dependencies to latest (#798)
Browse files Browse the repository at this point in the history
Updated all direct npm dependencies to `@latest`.

Observed changes:
- Prettier: now adds trailing commas to all lists.
prettier/prettier#11479
- Katas: `marked` now omits `id` attributes for header tags (confirmed
benign) markedjs/marked#2890
- Other trivial differences in JS emit through `esbuild`.

I was really hoping this would be a trivial process, but sadly it
wasn't. For posterity, here's what the process ended up being:

```js
const { execSync } = require("node:child_process");

function run(command) {
  console.log(`running command ${command}`);
  return execSync(command);
}

const deps = JSON.parse(run(`npm ls --package-lock-only --json`));

// Do these in this order first, otherwise @typescript-eslint/eslint-plugin
// gets really upset about the peer dependency missing
run("npm install @typescript-eslint/parser@latest");
run("npm install @typescript-eslint/eslint-plugin@latest");

// Update all direct deps to @latest
for (const depName of Object.keys(deps.dependencies)) {
  if (!depName.startsWith("qsharp")) {
    run(`npm install ${depName}@latest`);
  }
}

// Update indirect deps in package-lock.json
run("npm update");

// This fixes the workspace names in package-lock.json,
// which for some reason get erased above
run("npm install");

```

Ran `./build.py` to confirm the repo still built, discovered formatting
changes.

To reformat with new Prettier defaults:

```bash
npm run prettier:fix
```

Since we pulled a lot of JS tooling updates, I ran a quick script to
save the built artifacts so I could diff the JS output:

```bash
#!/bin/bash

set -e

# clean repo
git clean -fdx
rm -rf baseline-compare/
mkdir baseline-compare

# build
./build.py --wasm --npm --vscode --no-check --no-test

# npm
mkdir -p baseline-compare/npm
pushd npm
npm pack --pack-destination .
popd
tar -xzf npm/qsharp-lang-0.0.0.tgz -C baseline-compare/npm

# vsix
npm install -g @vscode/vsce
pushd vscode
vsce package --pre-release
popd
unzip vscode/qsharp-lang-vscode-dev-0.0.0.vsix -d baseline-compare/vscode

# commit baseline
cp package-lock.json baseline-compare/
git add baseline-compare/
git commit -m "Baseline for $(git rev-parse HEAD)"
```

Ran this script first on `main`, then with the updated `package.json` &
`package-lock.json`. Used `git` to diff the `baseline-compare` changes.
Confirmed they looked harmless.
  • Loading branch information
minestarks committed Oct 27, 2023
1 parent 36a4593 commit b43f3f4
Show file tree
Hide file tree
Showing 54 changed files with 1,048 additions and 1,130 deletions.
4 changes: 2 additions & 2 deletions jupyterlab/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
activate: async (
app: JupyterFrontEnd,
codemirrorLanguageRegistry: IEditorLanguageRegistry,
notebookTracker: INotebookTracker
notebookTracker: INotebookTracker,
) => {
registerQSharpLanguage(codemirrorLanguageRegistry);
registerQSharpNotebookHandlers(notebookTracker);
Expand All @@ -28,7 +28,7 @@ const plugin: JupyterFrontEndPlugin<void> = {
* and associates them with the qsharp CodeMirror mode.
*/
function registerQSharpLanguage(
codemirrorLanguageRegistry: IEditorLanguageRegistry
codemirrorLanguageRegistry: IEditorLanguageRegistry,
) {
const rules = [
{
Expand Down
2 changes: 1 addition & 1 deletion makeNpmDrop.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,5 @@ The main source file to show hooking up the compiler and Monaco on a web page is
The test files in "./npm/test/basics.js" show minimal examples of the qsharp compiler API usage.
`,
{ encoding: "utf8" }
{ encoding: "utf8" },
);
76 changes: 38 additions & 38 deletions npm/generate_katas_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ function tryGetTitleFromSegment(segment, errorPrefix) {
if (segment.type !== "markdown") {
throw new Error(
`${errorPrefix}\n` +
`segment is expected to be the title but found a segment of type '${segment.type}' instead`
`segment is expected to be the title but found a segment of type '${segment.type}' instead`,
);
}

Expand All @@ -50,7 +50,7 @@ function tryGetTitleFromSegment(segment, errorPrefix) {
throw new Error(
`${errorPrefix}\n` +
`A title segment must be 1 line, but ${linesCount} lines are present\n` +
`Hint: is the markdown missing a @[section] macro?`
`Hint: is the markdown missing a @[section] macro?`,
);
}
const title = tryGetTitleFromMarkdown(segment.markdown, errorPrefix);
Expand Down Expand Up @@ -103,18 +103,18 @@ function resolveSvgSegment(properties, baseFolderPath) {
const requiredProperties = ["path"];
const missingProperties = identifyMissingProperties(
properties,
requiredProperties
requiredProperties,
);
if (missingProperties.length > 0) {
throw new Error(
`SVG macro is missing the following properties: ${missingProperties}`
`SVG macro is missing the following properties: ${missingProperties}`,
);
}

const svgPath = join(baseFolderPath, properties.path);
const svg = tryReadFile(
svgPath,
`Could not read the contents of the SVG file at ${svgPath}`
`Could not read the contents of the SVG file at ${svgPath}`,
);

properties["svg"] = svg;
Expand All @@ -135,7 +135,7 @@ function appendToMarkdownSegment(markdownSegment, segmentToAppend) {
markdownSegment.markdown += "\n" + segmentToAppend.properties.svg;
} else {
throw new Error(
`Cannot append segment of type "${segmentToAppend.type}" into markdown segment`
`Cannot append segment of type "${segmentToAppend.type}" into markdown segment`,
);
}
}
Expand Down Expand Up @@ -165,7 +165,7 @@ function coalesceSegments(segments) {
if (currentSegment.type === "markdown" || currentSegment.type === "svg") {
coalescedSegment = coalesceIntoSingleMarkdownSegment(
currentSegment,
segmentsStack
segmentsStack,
);
} else {
coalescedSegment = currentSegment;
Expand Down Expand Up @@ -195,7 +195,7 @@ function parseMarkdown(markdown) {
const delta = match.index - latestProcessedIndex;
if (delta > 0) {
const textSegment = tryCreateMarkdownSegment(
markdown.substring(latestProcessedIndex, match.index)
markdown.substring(latestProcessedIndex, match.index),
);
if (textSegment !== null) {
segments.push(textSegment);
Expand All @@ -209,7 +209,7 @@ function parseMarkdown(markdown) {
} else {
// No more matches were found, create a text segment with the remaining content.
const textSegment = tryCreateMarkdownSegment(
markdown.substring(latestProcessedIndex, markdown.length)
markdown.substring(latestProcessedIndex, markdown.length),
);
if (textSegment !== null) {
segments.push(textSegment);
Expand All @@ -226,19 +226,19 @@ function createExample(baseFolderPath, properties) {
const requiredProperties = ["id", "codePath"];
const missingProperties = identifyMissingProperties(
properties,
requiredProperties
requiredProperties,
);
if (missingProperties.length > 0) {
throw new Error(
`Example macro is missing the following properties: ${missingProperties}`
`Example macro is missing the following properties: ${missingProperties}`,
);
}

// Generate the object using the macro properties.
const codePath = join(baseFolderPath, properties.codePath);
const code = tryReadFile(
codePath,
`Could not read the contents of the example code file at ${codePath}`
`Could not read the contents of the example code file at ${codePath}`,
);
return {
type: "example",
Expand All @@ -257,19 +257,19 @@ function createSolution(baseFolderPath, properties) {
const requiredProperties = ["id", "codePath"];
const missingProperties = identifyMissingProperties(
properties,
requiredProperties
requiredProperties,
);
if (missingProperties.length > 0) {
throw new Error(
`Solution macro is missing the following properties: ${missingProperties}`
`Solution macro is missing the following properties: ${missingProperties}`,
);
}

// Generate the object using the macro properties.
const codePath = join(baseFolderPath, properties.codePath);
const code = tryReadFile(
codePath,
`Could not read the contents of the solution code file at ${codePath}`
`Could not read the contents of the solution code file at ${codePath}`,
);
return {
type: "solution",
Expand All @@ -281,7 +281,7 @@ function createSolution(baseFolderPath, properties) {
function createExplainedSolution(markdownFilePath) {
const markdown = tryReadFile(
markdownFilePath,
`Could not read solution markdown file at ${markdownFilePath}`
`Could not read solution markdown file at ${markdownFilePath}`,
);

const solutionFolderPath = dirname(markdownFilePath);
Expand Down Expand Up @@ -312,7 +312,7 @@ function createExplainedSolution(markdownFilePath) {
function createAnswer(markdownFilePath) {
const markdown = tryReadFile(
markdownFilePath,
`Could not read answer markdown file at ${markdownFilePath}`
`Could not read answer markdown file at ${markdownFilePath}`,
);

const answerFolderPath = dirname(markdownFilePath);
Expand Down Expand Up @@ -340,21 +340,21 @@ function createQuestion(kataPath, properties) {
const requiredProperties = ["descriptionPath", "answerPath"];
const missingProperties = identifyMissingProperties(
properties,
requiredProperties
requiredProperties,
);
if (missingProperties.length > 0) {
throw new Error(
`Question macro is missing the following properties\n` +
`${missingProperties}\n` +
`Macro properties:\n` +
`${JSON.stringify(properties, undefined, 2)}`
`${JSON.stringify(properties, undefined, 2)}`,
);
}

// Generate the object using the macro properties.
const descriptionMarkdown = tryReadFile(
join(kataPath, properties.descriptionPath),
`Could not read descripton for question ${properties.id}`
`Could not read descripton for question ${properties.id}`,
);
const description = createTextContent(descriptionMarkdown);
const answer = createAnswer(join(kataPath, properties.answerPath));
Expand All @@ -378,33 +378,33 @@ function createExerciseSection(kataPath, properties, globalCodeSources) {
];
const missingProperties = identifyMissingProperties(
properties,
requiredProperties
requiredProperties,
);
if (missingProperties.length > 0) {
throw new Error(
`Exercise macro is missing the following properties\n` +
`${missingProperties}\n` +
`Macro properties:\n` +
`${JSON.stringify(properties, undefined, 2)}`
`${JSON.stringify(properties, undefined, 2)}`,
);
}

// Generate the object using the macro properties.
const descriptionMarkdown = tryReadFile(
join(kataPath, properties.descriptionPath),
`Could not read descripton for exercise ${properties.id}`
`Could not read descripton for exercise ${properties.id}`,
);
const description = createTextContent(descriptionMarkdown);
const resolvedCodePaths = properties.codePaths.map((path) =>
join(kataPath, path)
join(kataPath, path),
);
const sourceIds = aggregateSources(resolvedCodePaths, globalCodeSources);
const placeholderCode = tryReadFile(
join(kataPath, properties.placeholderSourcePath),
`Could not read placeholder code for exercise '${properties.id}'`
`Could not read placeholder code for exercise '${properties.id}'`,
);
const explainedSolution = createExplainedSolution(
join(kataPath, properties.solutionPath)
join(kataPath, properties.solutionPath),
);

return {
Expand All @@ -423,14 +423,14 @@ function createLessonSection(kataPath, properties, segmentsStack) {
const requiredProperties = ["id", "title"];
const missingProperties = identifyMissingProperties(
properties,
requiredProperties
requiredProperties,
);
if (missingProperties.length > 0) {
throw new Error(
`Section macro is missing the following properties\n` +
`${missingProperties}\n` +
`Macro properties:\n` +
`${JSON.stringify(properties, undefined, 2)}`
`${JSON.stringify(properties, undefined, 2)}`,
);
}

Expand All @@ -457,7 +457,7 @@ function createLessonSection(kataPath, properties, segmentsStack) {
throw new Error(
`Lesson item could not be generated for segment of type '${currentSegment.type}'\n` +
`segment:\n` +
`${JSON.stringify(currentSegment, undefined, 2)}`
`${JSON.stringify(currentSegment, undefined, 2)}`,
);
}

Expand All @@ -477,7 +477,7 @@ function createMacroSegment(match) {
const propertiesJson = match.groups.json;
const properties = tryParseJSON(
propertiesJson,
`Invalid JSON for macro of type ${type}.\n` + `JSON: ${propertiesJson}`
`Invalid JSON for macro of type ${type}.\n` + `JSON: ${propertiesJson}`,
);
return {
type,
Expand Down Expand Up @@ -511,13 +511,13 @@ function createKata(kataPath, id, title, segments, globalCodeSources) {
section = createExerciseSection(
kataPath,
currentSegment.properties,
globalCodeSources
globalCodeSources,
);
} else if (currentSegment.type === "section") {
section = createLessonSection(
kataPath,
currentSegment.properties,
segmentsStack
segmentsStack,
);
}

Expand All @@ -527,7 +527,7 @@ function createKata(kataPath, id, title, segments, globalCodeSources) {
`Unexpexted segment of type '${currentSegment.type}'\n` +
`segment:\n` +
`${JSON.stringify(currentSegment, undefined, 2)}\n` +
`Hint: is the markdown missing a @[section] macro?`
`Hint: is the markdown missing a @[section] macro?`,
);
}

Expand All @@ -546,7 +546,7 @@ function generateKataContent(path, globalCodeSources) {
const markdownPath = join(path, contentFileNames.kataMarkdown);
const markdown = tryReadFile(
markdownPath,
"Could not read the contents of the kata markdown file"
"Could not read the contents of the kata markdown file",
);

const kataId = basename(path);
Expand All @@ -556,7 +556,7 @@ function generateKataContent(path, globalCodeSources) {
const firstSegment = rawSegments.at(0);
const title = tryGetTitleFromSegment(
firstSegment,
`Could not get title for kata '${kataId}'`
`Could not get title for kata '${kataId}'`,
);

// Do not use the first segment since it was already processed to get the kata's title.
Expand Down Expand Up @@ -607,11 +607,11 @@ function generateKatasContent(katasPath, outputPath) {
const indexPath = join(katasPath, contentFileNames.katasIndex);
const indexJson = tryReadFile(
indexPath,
"Could not read the contents of the katas index file"
"Could not read the contents of the katas index file",
);
const katasDirs = tryParseJSON(
indexJson,
`Invalid katas index at ${indexPath}`
`Invalid katas index at ${indexPath}`,
);

// Initialize an object where all the global code sources will be aggregated.
Expand Down Expand Up @@ -654,7 +654,7 @@ function generateKatasContent(katasPath, outputPath) {
writeFileSync(
contentJsPath,
`export default ${JSON.stringify(katasContent, undefined, 2)}`,
"utf-8"
"utf-8",
);
}

Expand Down
2 changes: 1 addition & 1 deletion npm/generate_samples_content.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,5 @@ const contentPath = join(sampleGeneratedDir, "samples.generated.ts");
writeFileSync(
contentPath,
`export default ${JSON.stringify(result, undefined, 2)}`,
"utf-8"
"utf-8",
);
8 changes: 4 additions & 4 deletions npm/src/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ async function wasmLoader(uriOrBuffer: string | ArrayBuffer) {
}

export function loadWasmModule(
uriOrBuffer: string | ArrayBuffer
uriOrBuffer: string | ArrayBuffer,
): Promise<void> {
// Only initiate if not already in flight, to avoid race conditions
if (!wasmModulePromise) {
Expand Down Expand Up @@ -86,7 +86,7 @@ async function instantiateWasm() {
}

export async function getLibrarySourceContent(
path: string
path: string,
): Promise<string | undefined> {
await instantiateWasm();
return wasm.get_library_source_content(path);
Expand All @@ -101,7 +101,7 @@ export async function getDebugService(): Promise<IDebugService> {
// If the Worker was already created via other means and is ready to receive
// messages, then the worker may be passed in and it will be initialized.
export function getDebugServiceWorker(
workerArg: string | Worker
workerArg: string | Worker,
): IDebugServiceWorker {
if (!wasmModule) throw "Wasm module must be loaded first";

Expand Down Expand Up @@ -171,7 +171,7 @@ export async function getLanguageService(): Promise<ILanguageService> {
// If the Worker was already created via other means and is ready to receive
// messages, then the worker may be passed in and it will be initialized.
export function getLanguageServiceWorker(
workerArg: string | Worker
workerArg: string | Worker,
): ILanguageServiceWorker {
if (!wasmModule) throw "Wasm module must be loaded first";

Expand Down

0 comments on commit b43f3f4

Please sign in to comment.