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

[Storage] Enable VS Code Debugging for storage packages #2770

Merged
merged 21 commits into from
Jun 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions sdk/storage/storage-blob/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode"]
Copy link
Member

Choose a reason for hiding this comment

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

Great!

}
58 changes: 58 additions & 0 deletions sdk/storage/storage-blob/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Javascript Samples",
"program": "${workspaceFolder}/samples/javascript/basic.js",
"preLaunchTask": "npm: build:js-samples"
},
{
"type": "node",
"request": "launch",
"name": "Debug Typescript Samples",
"program": "${workspaceFolder}/samples/typescript/basic.ts",
"preLaunchTask": "npm: build:ts-samples",
"outFiles": ["${workspaceFolder}/dist-esm/samples/typescript/*.js"]
},
{
Copy link
Member

Choose a reason for hiding this comment

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

Is able to add a debug config to test "current" test file? Especially useful to debug one failed case in one file.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

Choose a reason for hiding this comment

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

Seems I didn't find it, where is the entry?

Copy link
Member Author

Choose a reason for hiding this comment

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

{
"type": "node",
"request": "launch",
"name": "Debug Mocha Test [Without Rollup]",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-r",
"ts-node/register",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/test/*.spec.ts"
],
"env": { "TS_NODE_COMPILER_OPTIONS": "{\"module\": \"commonjs\"}" },
"envFile": "${workspaceFolder}/../.env",

"type": "node",
"request": "launch",
"name": "Debug Mocha Test [Without Rollup]",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-r",
"ts-node/register",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/test/*.spec.ts"
],
"env": { "TS_NODE_COMPILER_OPTIONS": "{\"module\": \"commonjs\"}" },
"envFile": "${workspaceFolder}/../.env",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"protocol": "inspector"
},
{
"type": "node",
"request": "launch",
"name": "Debug Unit Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/dist-test/index.node.js"
],
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": "npm: build:test"
}
]
}
27 changes: 27 additions & 0 deletions sdk/storage/storage-blob/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.DS_Store": true
},
"[typescript]": {
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.detectIndentation": false
},
"[json]": {
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.detectIndentation": false
},
"[yaml]": {
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.detectIndentation": false
},
"editor.rulers": [
100
],
"typescript.preferences.quoteStyle": "double",
"javascript.preferences.quoteStyle": "double"
}
2 changes: 2 additions & 0 deletions sdk/storage/storage-blob/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
"build:browserzip": "gulp zip",
"build:es6": "tsc -p tsconfig.json",
"build:nodebrowser": "rollup -c 2>&1",
"build:js-samples": "npm run clean && npm run build:es6 && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:ts-samples": "npm run clean && cd samples && tsc -p . ",
Copy link
Member Author

Choose a reason for hiding this comment

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

For debugging the samples, build:js-samples & build:ts-samples are being added as prelaunch tasks in VSCode Debug config.
Is the nomenclature build:js-samples fine ?

Or something like build-samples:js & build-samples:ts?
(to be in sync with the alphabetical order of the scripts in package.json and still keep both of them together)
I'm not comfortable with the word build here. Maybe setup or something else, any suggestions ?

cc: @bsiegel

Copy link
Member

Choose a reason for hiding this comment

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

Those script names are fine, the build system doesn't care about any aside from the ones that are in the documentation. Personally I like those names.

I'm mildly curious why the build:js-samples seems to do the exact same thing as the regular "build" script (except it doesn't generate a zipfile).

Copy link
Member Author

Choose a reason for hiding this comment

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

@bsiegel

"build:es6": "tsc -p tsconfig.json",
"build:nodebrowser": "rollup -c 2>&1",
  • We import rolled-up src code in the js samples.
  • So, to execute/debug a sample, we need the rolled-up source code which is generated by npm run build:nodebrowser,
  • [ input for rollup is tsc compiled src code, which is obtained from npm run build:es6 ]

"build:js-samples": "npm run clean && npm run build:es6 && npm run build:nodebrowser",

In the command build:js-samples,
instead of doing npm run build:nodebrowser, we can just do cross-env ONLY_NODE=true rollup -c 2>&1 and successfully execute & debug the samples.

"build:test": "npm run build:es6 && rollup -c rollup.test.config.js 2>&1",
"build": "npm run build:es6 && npm run build:nodebrowser && npm run build:browserzip",
"check-format": "prettier --list-different --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-blob/samples/javascript/iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Setup: Enter your storage account name and shared key in main()
*/

const { BlobServiceClient, StorageClient, SharedKeyCredential } = require("../../src"); // Change to "@azure/storage-blob" in your package
const { BlobServiceClient, StorageClient, SharedKeyCredential } = require("../.."); // Change to "@azure/storage-blob" in your package

async function main() {
// Enter your storage account name and shared key
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-blob/samples/typescript/advanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Aborter,
BlobServiceClient,
StorageClient
} from "../.."; // Change to "@azure/storage-blob" in your package
} from "../../src"; // Change to "@azure/storage-blob" in your package
Copy link
Member Author

Choose a reason for hiding this comment

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

@jeremymeng
Compilation with tsc fails if the exact path "src", is not provided.

Copy link
Contributor

Choose a reason for hiding this comment

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

interesting. ts-node has no problem running it.

Copy link
Member Author

Choose a reason for hiding this comment

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

Update -
package.json - "build:samples": "cd samples && tsc -p ."

When the above script is executed as part of "preLaunchTask"[VSCode debug config], the execution fails when the exact path "src" is not provided.


async function main() {
// Fill in following settings before running this sample
Expand Down
14 changes: 4 additions & 10 deletions sdk/storage/storage-blob/samples/typescript/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
Models,
SharedKeyCredential,
StorageClient,
TokenCredential,
} from "../.."; // Change to "@azure/storage-blob" in your package
TokenCredential
} from "../../src"; // Change to "@azure/storage-blob" in your package

async function main() {
// Enter your storage account name and shared key
Expand Down Expand Up @@ -59,14 +59,8 @@ async function main() {
const blobName = "newblob" + new Date().getTime();
const blobClient = containerClient.createBlobClient(blobName);
const blockBlobClient = blobClient.createBlockBlobClient();
const uploadBlobResponse = await blockBlobClient.upload(
content,
content.length
);
console.log(
`Upload block blob ${blobName} successfully`,
uploadBlobResponse.requestId
);
const uploadBlobResponse = await blockBlobClient.upload(content, content.length);
console.log(`Upload block blob ${blobName} successfully`, uploadBlobResponse.requestId);

// List blobs
marker = undefined;
Expand Down
3 changes: 3 additions & 0 deletions sdk/storage/storage-file/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode"]
}
58 changes: 58 additions & 0 deletions sdk/storage/storage-file/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Javascript Samples",
"program": "${workspaceFolder}/samples/javascript/basic.js",
"preLaunchTask": "npm: build:js-samples"
},
{
"type": "node",
"request": "launch",
"name": "Debug Typescript Samples",
"program": "${workspaceFolder}/samples/typescript/basic.ts",
"preLaunchTask": "npm: build:ts-samples",
"outFiles": ["${workspaceFolder}/dist-esm/samples/typescript/*.js"]
},
{
"type": "node",
"request": "launch",
"name": "Debug Mocha Test [Without Rollup]",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-r",
"ts-node/register",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/test/*.spec.ts"
],
"env": { "TS_NODE_COMPILER_OPTIONS": "{\"module\": \"commonjs\"}" },
"envFile": "${workspaceFolder}/../.env",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"protocol": "inspector"
},
{
"type": "node",
"request": "launch",
"name": "Debug Unit Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/dist-test/index.node.js"
],
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": "npm: build:test"
}
]
}
27 changes: 27 additions & 0 deletions sdk/storage/storage-file/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.DS_Store": true
},
"[typescript]": {
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.detectIndentation": false
},
"[json]": {
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.detectIndentation": false
},
"[yaml]": {
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.detectIndentation": false
},
"editor.rulers": [
100
],
"typescript.preferences.quoteStyle": "double",
"javascript.preferences.quoteStyle": "double"
}
2 changes: 2 additions & 0 deletions sdk/storage/storage-file/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@
"build:browserzip": "gulp zip",
"build:es6": "tsc -p tsconfig.json",
"build:nodebrowser": "rollup -c 2>&1",
"build:js-samples": "npm run clean && npm run build:es6 && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:ts-samples": "npm run clean && cd samples && tsc -p . ",
"build:test": "npm run build:es6 && rollup -c rollup.test.config.js 2>&1",
"build": "npm run build:es6 && npm run build:nodebrowser && npm run build:browserzip",
"check-format": "prettier --list-different --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
Expand Down
21 changes: 5 additions & 16 deletions sdk/storage/storage-file/samples/typescript/advanced.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@
*/

import fs from "fs";
import {
Aborter,
AnonymousCredential,
FileServiceClient,
StorageClient
} from "../.."; // Change to "@azure/storage-file" in your package
import { Aborter, AnonymousCredential, FileServiceClient, StorageClient } from "../../src"; // Change to "@azure/storage-file" in your package

async function main() {
// Fill in following settings before running this sample
Expand Down Expand Up @@ -56,16 +51,10 @@ async function main() {

// Parallel uploading a Readable stream with FileClient.uploadStream() in Node.js runtime
// FileClient.uploadStream() is only available in Node.js
await fileClient.uploadStream(
fs.createReadStream(localFilePath),
fileSize,
4 * 1024 * 1024,
20,
{
abortSignal: Aborter.timeout(30 * 60 * 1000), // Abort uploading with timeout in 30mins
progress: (ev: any) => console.log(ev)
}
);
await fileClient.uploadStream(fs.createReadStream(localFilePath), fileSize, 4 * 1024 * 1024, 20, {
abortSignal: Aborter.timeout(30 * 60 * 1000), // Abort uploading with timeout in 30mins
progress: (ev: any) => console.log(ev)
});
console.log("uploadStream success");

// Parallel uploading a browser File/Blob/ArrayBuffer in browsers with FileClient.uploadBrowserData()
Expand Down
7 changes: 1 addition & 6 deletions sdk/storage/storage-file/samples/typescript/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@
Setup: Enter your storage account name and shared key in main()
*/

import {
StorageClient,
FileServiceClient,
SharedKeyCredential,
Models,
} from "../.."; // Change to "@azure/storage-file" in your package
import { StorageClient, FileServiceClient, SharedKeyCredential, Models } from "../../src"; // Change to "@azure/storage-file" in your package

async function main() {
// Enter your storage account name and shared key
Expand Down
3 changes: 3 additions & 0 deletions sdk/storage/storage-queue/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["esbenp.prettier-vscode"]
}
58 changes: 58 additions & 0 deletions sdk/storage/storage-queue/.vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Debug Javascript Samples",
"program": "${workspaceFolder}/samples/javascript/basic.js",
"preLaunchTask": "npm: build:js-samples"
},
{
"type": "node",
"request": "launch",
"name": "Debug Typescript Samples",
"program": "${workspaceFolder}/samples/typescript/basic.ts",
"preLaunchTask": "npm: build:ts-samples",
"outFiles": ["${workspaceFolder}/dist-esm/samples/typescript/*.js"]
},
{
"type": "node",
"request": "launch",
"name": "Debug Mocha Test [Without Rollup]",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-r",
"ts-node/register",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/test/*.spec.ts"
],
"env": { "TS_NODE_COMPILER_OPTIONS": "{\"module\": \"commonjs\"}" },
"envFile": "${workspaceFolder}/../.env",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"protocol": "inspector"
},
{
"type": "node",
"request": "launch",
"name": "Debug Unit Tests",
"program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
"args": [
"-u",
"tdd",
"--timeout",
"999999",
"--colors",
"${workspaceFolder}/dist-test/index.node.js"
],
"internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": "npm: build:test"
}
]
}
27 changes: 27 additions & 0 deletions sdk/storage/storage-queue/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"files.exclude": {
"**/.git": true,
"**/.svn": true,
"**/.DS_Store": true
},
"[typescript]": {
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.detectIndentation": false
},
"[json]": {
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.detectIndentation": false
},
"[yaml]": {
"editor.formatOnSave": true,
"editor.tabSize": 2,
"editor.detectIndentation": false
},
"editor.rulers": [
100
],
"typescript.preferences.quoteStyle": "double",
"javascript.preferences.quoteStyle": "double"
}
2 changes: 2 additions & 0 deletions sdk/storage/storage-queue/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@
"build:browserzip": "gulp zip",
"build:es6": "tsc -p tsconfig.json",
"build:nodebrowser": "rollup -c 2>&1",
"build:js-samples": "npm run clean && npm run build:es6 && cross-env ONLY_NODE=true rollup -c 2>&1",
"build:ts-samples": "npm run clean && cd samples && tsc -p . ",
"build:test": "npm run build:es6 && rollup -c rollup.test.config.js 2>&1",
"build": "npm run build:es6 && npm run build:nodebrowser && npm run build:browserzip",
"check-format": "prettier --list-different --config ../../.prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
Expand Down