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] Rollup for tests in storage #2297

Merged
merged 45 commits into from
May 15, 2019
Merged
Show file tree
Hide file tree
Changes from 39 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
5663490
Rename test files for consistency
HarshaNalluru Apr 16, 2019
0fb1846
rollup for node tests
HarshaNalluru Apr 16, 2019
558cac6
rollup for node tests
HarshaNalluru Apr 16, 2019
e6803cb
this is undefined, update paths for rollup
HarshaNalluru Apr 16, 2019
9042ef6
Import dotenv in index.ts
HarshaNalluru Apr 16, 2019
9471ef0
Update output path in rollup
HarshaNalluru Apr 16, 2019
44570b2
del mocha report conf - pass args in live test cmd
HarshaNalluru Apr 16, 2019
e72f5cd
restructure package.json similar to other pkgs
HarshaNalluru Apr 16, 2019
154af83
remove commented code
HarshaNalluru Apr 16, 2019
66a5fed
Add mocha.reporter.config to publish node results
HarshaNalluru Apr 16, 2019
6d2fc3f
Merge remote-tracking branch 'upstream/master' into RollupStorage
HarshaNalluru Apr 22, 2019
6363eb4
Remove unwanted warnings, code for min version
HarshaNalluru Apr 22, 2019
93e42fc
Update gulp to zip both min and unmin versions
HarshaNalluru Apr 22, 2019
7bddadf
Update rollup to generate min and unmin versions
HarshaNalluru Apr 22, 2019
0a311f9
Add (commented) rollup visualizer
HarshaNalluru Apr 22, 2019
4fecbcc
remove unused import path
HarshaNalluru Apr 23, 2019
4eba327
remove unnecessary comment
HarshaNalluru Apr 23, 2019
3665dd4
Merge remote-tracking branch 'upstream/master' into RollupStorage
HarshaNalluru Apr 23, 2019
9921461
Update rollup for tests in storage-file
HarshaNalluru Apr 23, 2019
606fe5c
Update rollup for tests in storage-queue
HarshaNalluru Apr 23, 2019
7899e4c
add rollup-plugin-json in devdependency
HarshaNalluru Apr 23, 2019
ed5fc86
Update coverage commands
HarshaNalluru Apr 23, 2019
fb5970d
Merge remote-tracking branch 'upstream/master' into RollupStorage
HarshaNalluru Apr 24, 2019
ac390da
Update nycrc for code coverage - storage-blob
HarshaNalluru Apr 30, 2019
ce2e0b6
Update .nycrc - code coverage -storage{file,queue}
HarshaNalluru Apr 30, 2019
6ce31db
resolve merge conflicts
HarshaNalluru Apr 30, 2019
e9d95fc
Update test:node command - storage-blob
HarshaNalluru Apr 30, 2019
d9c9456
Add rollup-plugin-json
HarshaNalluru Apr 30, 2019
9ac4f0f
Update package.json as per rush
HarshaNalluru Apr 30, 2019
34e9fc5
Increase timeout to 120 seconds for tests
HarshaNalluru Apr 30, 2019
7d2b4ba
resolve merge conflicts
HarshaNalluru May 7, 2019
3237181
resolve merge conflicts
HarshaNalluru May 7, 2019
7788fd0
Update JavaScript Bundle file names
HarshaNalluru May 7, 2019
0e2d10d
Update test path in karma conf
HarshaNalluru May 7, 2019
cf6524c
Merge remote-tracking branch 'upstream/master' into RollupStorage
HarshaNalluru May 8, 2019
518a1f0
undo adding rollup-plugin-json for storage-pkgs
HarshaNalluru May 8, 2019
3dd97f2
resolve merge conflicts
HarshaNalluru May 8, 2019
fb50e69
Update test command as the per updates to master
HarshaNalluru May 8, 2019
ea3b017
Merge branch 'master' into RollupStorage
HarshaNalluru May 8, 2019
21f1302
Resolve merge conflicts
HarshaNalluru May 10, 2019
10b71ee
Merge branch 'RollupStorage' of https://github.com/HarshaNalluru/azur…
HarshaNalluru May 10, 2019
2d2c526
remove onwarn handler, update with context="null"
HarshaNalluru May 13, 2019
312b42b
Merge branch 'master' into RollupStorage
HarshaNalluru May 13, 2019
5a630c7
Merge branch 'master' into RollupStorage
HarshaNalluru May 14, 2019
c7f913e
Merge branch 'master' into RollupStorage
HarshaNalluru May 15, 2019
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
6 changes: 3 additions & 3 deletions sdk/storage/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ const Azure = require("@azure/storage-blob");
To use the SDK with JS bundle in the browsers, simply add a script tag to your HTML pages pointing to the downloaded JS bundle file(s):

```html
<script src="https://mydomain/azure-storage.blob.min.js"></script>
<script src="https://mydomain/azure-storage.file.min.js"></script>
<script src="https://mydomain/azure-storage.queue.min.js"></script>
<script src="https://mydomain/azure-storage-blob.min.js"></script>
<script src="https://mydomain/azure-storage-file.min.js"></script>
<script src="https://mydomain/azure-storage-queue.min.js"></script>
```

The JS bundled file is compatible with [UMD](https://github.com/umdjs/umd) standard, if no module system found, following global variable(s) will be exported:
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/storage-blob/.npmignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# browser #
browser/azure-storage.blob.js
browser/azure-storage.blob.js.map
browser/azure-storage-blob.js
browser/azure-storage-blob.js.map

# dist-test #
dist-test/
Expand Down
3 changes: 2 additions & 1 deletion sdk/storage/storage-blob/.nycrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"include": [
"src/**/*.ts"
"dist-test/index.node.js"
],
"exclude": [
"**/*.d.ts",
Expand All @@ -21,6 +21,7 @@
"html",
"cobertura"
],
"exclude-after-remap":false,
Copy link
Member Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

OK, how does coverage report look like? Do covered lines point to TS source code or compiled JS codes?

Copy link
Member Author

Choose a reason for hiding this comment

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

Covered lines would point to the typescript source code.

Example -
Coverage output-html for (only) one test -

image
image

"sourceMap": true,
"instrument": true,
"all": true
Expand Down
2 changes: 1 addition & 1 deletion sdk/storage/storage-blob/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ const Azure = require("@azure/storage-blob");
To use the SDK with JS bundle in the browsers, simply add a script tag to your HTML pages pointing to the downloaded JS bundle file(s):

```html
<script src="https://mydomain/azure-storage.blob.min.js"></script>
<script src="https://mydomain/azure-storage-blob.min.js"></script>
```

The JS bundled file is compatible with [UMD](https://github.com/umdjs/umd) standard, if no module system found, following global variable(s) will be exported:
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/storage-blob/gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const zipFileName = `azurestoragejs.blob-${version}.zip`;
gulp.task("zip", function(callback) {
gulp
.src([
"browser/azure-storage.blob.js",
"browser/azure-storage.blob.min.js",
"browser/azure-storage-blob.min.js",
Copy link
Member

Choose a reason for hiding this comment

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

Please update section "JavaScript Bundle" in "readme.md". Same with other readme.md files for queue/file. Please check any documents points to old bundle name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks for pointing out.
Done - 7788fd0

"browser/azure-storage-blob.js",
"browser/*.txt"
])
.pipe(zip(zipFileName))
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/storage-blob/karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// https://github.com/karma-runner/karma-chrome-launcher
process.env.CHROME_BIN = require("puppeteer").executablePath();
require("dotenv").config({path:"../.env"});
require("dotenv").config({ path: "../.env" });

module.exports = function(config) {
config.set({
Expand Down Expand Up @@ -65,7 +65,7 @@ module.exports = function(config) {

// Exclude coverage calculation for following files
remapOptions: {
exclude: /node_modules|tests/g
exclude: /node_modules|test/g
},

junitReporter: {
Expand Down
4 changes: 2 additions & 2 deletions sdk/storage/storage-blob/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"main": "./dist/index.js",
"module": "./dist-esm/src/index.js",
"browser": {
"./dist/index.js": "./browser/azure-storage.blob.min.js",
"./dist/index.js": "./browser/azure-storage-blob.min.js",
"./dist-esm/src/index.js": "./dist-esm/src/index.browser.js",
"./dist-esm/test/utils/index.js": "./dist-esm/test/utils/index.browser.js",
"./dist-esm/src/BlobDownloadResponse.js": "./dist-esm/src/BlobDownloadResponse.browser.js",
Expand Down Expand Up @@ -78,7 +78,7 @@
"extract-api": "tsc -p . && api-extractor run --local",
"format": "prettier --write --config .prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"integration-test:browser": "karma start --single-run",
"integration-test:node": "cross-env TS_NODE_COMPILER_OPTIONS=\"{\\\"module\\\": \\\"commonjs\\\"}\" nyc mocha --compilers ts-node/register --require source-map-support/register --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=- --full-trace --no-timeouts test/*.test.ts test/node/*.test.ts",
"integration-test:node": "nyc mocha --require source-map-support/register --reporter mocha-multi --reporter-options spec=-,mocha-junit-reporter=- --full-trace -t 120000 dist-test/index.node.js",
"integration-test": "npm run integration-test:node && npm run integration-test:browser",
"lint:fix": "echo skipped",
"lint": "echo skipped",
Expand Down
174 changes: 174 additions & 0 deletions sdk/storage/storage-blob/rollup.base.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import nodeResolve from "rollup-plugin-node-resolve";
import multiEntry from "rollup-plugin-multi-entry";
import cjs from "rollup-plugin-commonjs";
import replace from "rollup-plugin-replace";
import { uglify } from "rollup-plugin-uglify";
import sourcemaps from "rollup-plugin-sourcemaps";
import shim from "rollup-plugin-shim";
// import visualizer from "rollup-plugin-visualizer";

const version = require("./package.json").version;
const banner = [
"/*!",
` * Azure Storage SDK for JavaScript - Blob, ${version}`,
" * Copyright (c) Microsoft and contributors. All rights reserved.",
" */"
].join("\n");

const pkg = require("./package.json");
const depNames = Object.keys(pkg.dependencies);
const production = process.env.NODE_ENV === "production";

export function nodeConfig(test = false) {
const externalNodeBuiltins = [
"@azure/ms-rest-js",
"crypto",
"fs",
"events",
"os",
"stream"
];
const baseConfig = {
input: "dist-esm/src/index.js",
external: depNames.concat(externalNodeBuiltins),
output: {
file: "dist/index.js",
format: "cjs",
sourcemap: true
},
preserveSymlinks: false,
plugins: [
sourcemaps(),
Copy link
Member

Choose a reason for hiding this comment

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

What does "sourcemaps()" do? I remembered a sourcemap file is generated under dist folder without this plugin.

Copy link
Member Author

Choose a reason for hiding this comment

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

This plugin helps in grabbing source maps from sourceMappingURLs.

For instance, look at the differences in nyc code coverage output.

  • with sourcemaps()
    image

  • without sourcemaps()
    image

Copy link
Member

Choose a reason for hiding this comment

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

Got it. Can you remove "dotenv" from coverage report?

Copy link
Member

Choose a reason for hiding this comment

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

sourcemaps is for threading the sourcemap across multiple transformations. Rollup by default won't consume sourcemaps so the dist sourcemaps would be a mapping to dist-esm rather than the original TS code.

Copy link
Member Author

Choose a reason for hiding this comment

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

Got it. Can you remove "dotenv" from coverage report?

Update -

I tried excluding that specific file(and every possible node_modules path) by adding rules in .nycrc file and could not exclude this file in any way.

Looks like nyc is not properly honouring the exclude rule in .nycrc. I see some similar recent user issues in the nyc repo - istanbuljs/nyc#1099

I'm opening a new issue to investigate further - #2820

Choose a reason for hiding this comment

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

@HarshaNalluru - I apologize. The issue 1099 that you reference was mine. It was user error.

replace({
delimiters: ["", ""],
values: {
// replace dynamic checks with if (true) since this is for node only.
// Allows rollup's dead code elimination to be more aggressive.
"if (isNode)": "if (true)"
}
}),
nodeResolve({ preferBuiltins: true }),
cjs()
]
};

if (test) {
// entry point is every test file
baseConfig.input = [
"dist-esm/test/*.spec.js",
"dist-esm/test/node/*.spec.js"
];
baseConfig.plugins.unshift(multiEntry({ exports: false }));

// different output file
baseConfig.output.file = "dist-test/index.node.js";

// mark assert as external
baseConfig.external.push("assert", "fs", "path");

baseConfig.onwarn = warning => {
Copy link
Member

Choose a reason for hiding this comment

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

Interesting, for 10.1.0-preview, we have similar roll up config for Node.js test cases. However, doesn't have met this "THIS_IS_UNDEFINED" warning. Can you check why previous version doesn't have this issue?

See https://github.com/Azure/azure-storage-js/blob/v10.1.0-preview-blob/blob/rollup.test.config.js

Copy link
Member

Choose a reason for hiding this comment

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

It's possible this ignore was added because it was needed in other projects and isn't needed here. Harsha can confirm.

Copy link
Member Author

Choose a reason for hiding this comment

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

We do see "THIS_IS_UNDEFINED" warning which I could only get rid of using custom onwarn handlers.
Also, I've verified v10.1.0-preview branch, I need to look deeper on why it didn't throw those warnings previously.
I'm guessing this might be from version updates in the dependencies[not really sure].

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 -

From the documentation https://rollupjs.org/guide/en#danger-zone, it is not clear to me on what context = "null" does.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @HarshaNalluru ! Here is the description about "THIS NOT DEFINED" in rollup doc. options.context is a workaround to override default value of this. @bterlson previously added node.context = "null" in v10.1.0-preview. I believe this approach should work.

Error: "this is undefined"
In a JavaScript module, this is undefined at the top level (i.e., outside functions). Because of that, Rollup will rewrite any this references to undefined so that the resulting behaviour matches what will happen when modules are natively supported.

There are occasional valid reasons for this to mean something else. If you're getting errors in your bundle, you can use options.context and options.moduleContext to change this behaviour.

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed onwarn handlers and updated with context = "null"
2d2c526

if (warning.code === "THIS_IS_UNDEFINED") {
// This error happens frequently due to TypeScript emitting `this` at the
// top-level of a module. In this case its fine if it gets rewritten to
// undefined, so ignore this error.
return;
}

console.error(`(!) ${warning.message}`);
};
} else if (production) {
baseConfig.plugins.push(uglify());
Copy link
Member

Choose a reason for hiding this comment

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

For Node.js, we released minified CJS bundle to customers. When there is an exception in SDK, stack trace is unreadable. Any good suggestions? @bterlson @jeremymeng @HarshaNalluru

Copy link
Member

Choose a reason for hiding this comment

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

Sourcemaps! See below.

}

return baseConfig;
}

export function browserConfig(test = false, production = false) {
const baseConfig = {
input: "dist-esm/src/index.browser.js",
external: ["ms-rest-js"],
output: {
file: "browser/azure-storage-blob.js",
banner: banner,
format: "umd",
name: "azblob",
Copy link
Member

Choose a reason for hiding this comment

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

Just a note: this will likely change to align with .net naming conventions. Expect something like Azure.Storage.Blob instead, but let's keep it the same for now.

Copy link
Member

Choose a reason for hiding this comment

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

Please don't change this before next breaking change. : )

sourcemap: true
},
preserveSymlinks: false,
plugins: [
sourcemaps(),
replace({
delimiters: ["", ""],
values: {
// replace dynamic checks with if (false) since this is for
// browser only. Rollup's dead code elimination will remove
// any code guarded by if (isNode) { ... }
"if (isNode)": "if (false)"
}
}),
// os is not used by the browser bundle, so just shim it
shim({
Copy link
Member

Choose a reason for hiding this comment

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

Are these shims actually needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

  • dotenv is needed
  • os is present from the beginning

Update - shimming both of them is required.

dotenv: `export function config() { }`,
os: `
export const type = 1;
export const release = 1;
`
}),
nodeResolve({
mainFields: ["module", "browser"],
preferBuiltins: false
}),
cjs({
namedExports: {
events: ["EventEmitter"],
assert: [
"ok",
"deepEqual",
"equal",
"fail",
"deepStrictEqual",
"notDeepEqual"
]
}
})
]
};

if (test) {
baseConfig.input = [
"dist-esm/test/*.spec.js",
"dist-esm/test/browser/*.spec.js"
];
baseConfig.plugins.unshift(multiEntry({ exports: false }));
baseConfig.output.file = "dist-test/index.browser.js";
baseConfig.onwarn = warning => {
if (warning.code === "THIS_IS_UNDEFINED") {
// This error happens frequently due to TypeScript emitting `this` at the
// top-level of a module. In this case its fine if it gets rewritten to
// undefined, so ignore this error.
return;
}

console.error(`(!) ${warning.message}`);
};
} else if (production) {
baseConfig.output.file = "browser/azure-storage-blob.min.js";
baseConfig.plugins.push(
uglify({
output: {
preamble: banner
}
})
// Comment visualizer because it only works on Node.js 8+; Uncomment it to get bundle analysis report
// visualizer({
// filename: "./statistics.html",
// sourcemap: true
// })
);
}

return baseConfig;
}
110 changes: 13 additions & 97 deletions sdk/storage/storage-blob/rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,102 +1,18 @@
import nodeResolve from "rollup-plugin-node-resolve";
import { uglify } from "rollup-plugin-uglify";
import replace from "rollup-plugin-replace";
import commonjs from "rollup-plugin-commonjs";
import shim from "rollup-plugin-shim";
// import visualizer from "rollup-plugin-visualizer";
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

const version = require("./package.json").version;
const banner = [
"/*!",
` * Azure Storage SDK for JavaScript - Blob, ${version}`,
" * Copyright (c) Microsoft and contributors. All rights reserved.",
" */"
].join("\n");
import * as base from "./rollup.base.config";

const nodeRollupConfigFactory = () => {
return {
external: ["@azure/ms-rest-js", "crypto", "fs", "events", "os", "stream"],
input: "dist-esm/src/index.js",
output: {
file: "dist/index.js",
format: "cjs",
sourcemap: true
},
preserveSymlinks: false,
plugins: [nodeResolve(), uglify()]
};
};
const inputs = [];

const browserRollupConfigFactory = isProduction => {
const browserRollupConfig = {
input: "dist-esm/src/index.browser.js",
output: {
file: "browser/azure-storage.blob.js",
banner: banner,
format: "umd",
name: "azblob",
sourcemap: true
},
preserveSymlinks: false,
plugins: [
replace({
delimiters: ["", ""],
values: {
// replace dynamic checks with if (false) since this is for
// browser only. Rollup's dead code elimination will remove
// any code guarded by if (isNode) { ... }
"if (isNode)": "if (false)"
}
}),
// os is not used by the browser bundle, so just shim it
shim({
dotenv: `export function config() { }`,
os: `
export const type = 1;
export const release = 1;
`
}),
nodeResolve({
mainFields: ['module', 'browser'],
preferBuiltins: false
}),
commonjs({
namedExports: {
events: ["EventEmitter"],
assert: [
"ok",
"deepEqual",
"equal",
"fail",
"deepStrictEqual",
"notDeepEqual"
]
}
})
]
};
if (!process.env.ONLY_BROWSER) {
inputs.push(base.nodeConfig());
}

if (isProduction) {
browserRollupConfig.output.file = "browser/azure-storage.blob.min.js";
browserRollupConfig.plugins.push(
uglify({
output: {
preamble: banner
}
})
// Comment visualizer because it only works on Node.js 8+; Uncomment it to get bundle analysis report
// visualizer({
// filename: "./statistics.html",
// sourcemap: true
// })
);
}
// Disable this until we are ready to run rollup for the browser.
if (!process.env.ONLY_NODE) {
inputs.push(base.browserConfig());
inputs.push(base.browserConfig(false, true));
}

return browserRollupConfig;
};

export default [
browserRollupConfigFactory(false),
browserRollupConfigFactory(true),
nodeRollupConfigFactory()
];
export default inputs;