Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
dc5f0d8
Move aborter to its own library
bterlson Apr 30, 2019
2ef4d4d
Make consistent versions for rollup plugins and typescript
bterlson Apr 30, 2019
2ea1034
Tests for aborter
bterlson Apr 30, 2019
e2b77ec
Update readme
bterlson Apr 30, 2019
568eeb7
Unify @types/node version to ^8.0.0
jeremymeng May 7, 2019
91f3e2d
Add Aborter tests
jeremymeng May 7, 2019
5e44428
Enable browser
jeremymeng May 7, 2019
81359a4
Fix file paths
jeremymeng May 7, 2019
8573582
Run "format" script
jeremymeng May 7, 2019
944b2e0
Apply Brandon's pnpm fix
jeremymeng May 7, 2019
1bce4c3
Merge branch 'master' of https://github.com/Azure/azure-sdk-for-js in…
jeremymeng May 7, 2019
9dbb68c
Fix types file path
jeremymeng May 7, 2019
c388512
Update file and queue to use the @azure/core-aborter dependency
jeremymeng May 7, 2019
757a231
Remove aborter tests in blob/file/queue
jeremymeng May 7, 2019
3325839
[Storage-Blob] Rename clients from *URL => *Client (#2874)
jeremymeng May 15, 2019
7cad284
[Storage-file] Rename *URL to *Client (#2877)
jeremymeng May 15, 2019
4562d8e
Merge remote-tracking branch 'upstream/feature/storage' into feature-…
jeremymeng May 15, 2019
f59ecdd
[Storage-queue] Rename *URL to *Client (#2911)
jeremymeng May 16, 2019
0186e89
Follow up rename: ServiceClient to BlobServiceClient (#2917)
jeremymeng May 16, 2019
63b7643
Merge remote-tracking branch 'upstream/feature/storage' into rush_abs…
jeremymeng May 17, 2019
24a09a2
Fix errors and warnings
jeremymeng May 17, 2019
41ee2f6
Fix merging errors
jeremymeng May 17, 2019
738e3d2
Improve package.json
jeremymeng May 17, 2019
d3c2844
Make npm scripts to follow convention
jeremymeng May 17, 2019
2c922b5
Add LICENSE file
jeremymeng May 17, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions sdk/core/aborter/.prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"tabWidth": 2,
"singleQuote": false,
"arrowParens": "always",
"printWidth": 100
}
28 changes: 28 additions & 0 deletions sdk/core/aborter/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "@azure/core-aborter",
"version": "1.0.0",
"description": "",
"main": "./dist/index.js",
"scripts": {
"build": "tsc -p . && rollup -c ./rollup.config.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"types": "./typings/Aborter.d.ts",
"keywords": [],
"author": "",
"license": "ISC",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I guess this is from npm init and we use MIT?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

good catch, also need LICENSE file.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed

"dependencies": {
"@azure/ms-rest-js": "^1.2.6"
},
"devDependencies": {
"rollup": "^1.0.0",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-multi-entry": "^2.1.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-uglify": "^6.0.0",
"typescript": "^3.2.2"
}
}
128 changes: 128 additions & 0 deletions sdk/core/aborter/rollup.base.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
// 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 json from "rollup-plugin-json";
import replace from "rollup-plugin-replace";
import { uglify } from "rollup-plugin-uglify";
import sourcemaps from "rollup-plugin-sourcemaps";

import path from "path";

const pkg = require("./package.json");
const depNames = Object.keys(pkg.dependencies);
const input = "./dist-esm/Aborter.js";
const production = process.env.NODE_ENV === "production";

export function nodeConfig(test = false) {
const externalNodeBuiltins = ["events", "util", "os"];
const baseConfig = {
input: input,
external: depNames.concat(externalNodeBuiltins),
output: { file: "dist/index.js", format: "cjs", sourcemap: true },
plugins: [
sourcemaps(),
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, main: false }),
cjs(),
json()
]
};

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

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

// mark assert as external
baseConfig.external.push(
"assert",
"fs",
"path",
"@azure/arm-servicebus",
"@azure/ms-rest-nodeauth"
);

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;
}

if (
warning.code === "CIRCULAR_DEPENDENCY" &&
warning.importer.indexOf(path.normalize("node_modules/chai/lib") === 0)
) {
// Chai contains circular references, but they are not fatal and can be ignored.
return;
}

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

return baseConfig;
}

export function browserConfig(test = false) {
const baseConfig = {
input: input,
external: ["ms-rest-js"],
output: {
file: "browser/index.js",
format: "umd",
name: "Aborter",
sourcemap: true,
globals: { "ms-rest-js": "msRest" }
},
plugins: [
sourcemaps(),
replace(
// ms-rest-js is externalized so users must include it prior to using this bundle.
{
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)"
}
}
),
nodeResolve({
preferBuiltins: false,
browser: true
}),
cjs({
namedExports: { events: ["EventEmitter"] }
}),
json()
]
};

if (test) {
baseConfig.input = "dist-esm/test/**/*.spec.js";
baseConfig.plugins.unshift(multiEntry({ exports: false }));
baseConfig.output.file = "test-browser/index.js";
} else if (production) {
baseConfig.plugins.push(uglify());
}

return baseConfig;
}
17 changes: 17 additions & 0 deletions sdk/core/aborter/rollup.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as base from "./rollup.base.config";

const inputs = [];

if (!process.env.ONLY_BROWSER) {
inputs.push(base.nodeConfig());
}

// Disable this until we are ready to run rollup for the browser.
// if (!process.env.ONLY_NODE) {
// inputs.push(base.browserConfig());
// }

export default inputs;
6 changes: 6 additions & 0 deletions sdk/core/aborter/rollup.test.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as base from "./rollup.base.config";

export default [base.nodeConfig(true)];
95 changes: 95 additions & 0 deletions sdk/core/aborter/sbpkg.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
{
"name": "@azure/service-bus",
"author": "Microsoft Corporation",
"version": "1.0.0-preview.2",
"license": "MIT",
"description": "Azure Service Bus SDK for Node.js",
"homepage": "https://github.com/Azure/azure-sdk-for-js/tree/master/sdk/servicebus/service-bus",
"repository": "github:Azure/azure-sdk-for-js",
"keywords": [
"azure",
"cloud",
"service bus",
"AMQP"
],
"bugs": {
"url": "https://github.com/azure/azure-sdk-for-js/issues"
},
"main": "./dist/index.js",
"module": "dist-esm/src/index.js",
"types": "./typings/src/index.d.ts",
"engine": {
"node": ">=6.0.0"
},
"dependencies": {
"@azure/amqp-common": "^1.0.0-preview.2",
"@azure/ms-rest-nodeauth": "^0.9.2",
"@types/long": "^4.0.0",
"debug": "^3.1.0",
"is-buffer": "^2.0.3",
"long": "^4.0.0",
"rhea": "^1.0.4",
"rhea-promise": "^0.1.15",
"tslib": "^1.9.3"
},
"devDependencies": {
"@azure/arm-servicebus": "^0.1.0",
"@microsoft/api-extractor": "^6.3.0",
"@types/async-lock": "^1.1.0",
"@types/chai": "^4.1.6",
"@types/chai-as-promised": "^7.1.0",
"@types/debug": "^0.0.31",
"@types/dotenv": "^6.1.0",
"@types/mocha": "^5.2.5",
"@types/node": "^8.0.0",
"chai": "^4.2.0",
"chai-as-promised": "^7.1.1",
"cross-env": "^5.2.0",
"dotenv": "^7.0.0",
"mocha": "^5.2.0",
"mocha-junit-reporter": "^1.18.0",
"mocha-multi": "^1.0.1",
"nyc": "^14.0.0",
"prettier": "^1.16.4",
"rimraf": "^2.6.2",
"rollup": "^1.0.0",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-json": "^3.1.0",
"rollup-plugin-multi-entry": "^2.1.0",
"rollup-plugin-node-resolve": "^4.0.0",
"rollup-plugin-replace": "^2.1.0",
"rollup-plugin-sourcemaps": "^0.4.2",
"rollup-plugin-uglify": "^6.0.0",
"ts-node": "^7.0.1",
"tslint": "^5.15.0",
"typescript": "^3.2.2"
},
"files": [
"LICENSE",
"changelog.md",
"Readme.md",
"dist/",
"dist-esm/src/",
"src/",
"typings/"
],
"scripts": {
"build-browser": "tsc -p . && cross-env ONLY_BROWSER=true rollup -c 2>&1",
"build-node": "tsc -p . && cross-env ONLY_NODE=true rollup -c 2>&1",
"build-samples": "node .scripts/prepSamples.js && cd samples && tsc -p .",
"build-test": "tsc -p . && cross-env ONLY_NODE=true rollup -c rollup.test.config.js 2>&1",
"build": "tsc -p . && rollup -c 2>&1",
"check-format": "prettier --list-different --config .prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"clean": "rimraf dist dist-esm test-dist typings *.tgz *.log",
"coverage": "npm run build-test && nyc --reporter=lcov mocha -t 120000 test-dist/index.js",
"extract-api": "tsc -p . && api-extractor run --local",
"format": "prettier --write --config .prettierrc.json \"src/**/*.ts\" \"test/**/*.ts\" \"*.{js,json}\"",
"lint": "tslint -p . -c tslint.json",
"pack": "npm pack 2>&1",
"prebuild": "npm run clean",
"pretest": "npm run build-test",
"test": "npm run build",
"tsc": "tsc",
"unit-node": "npm run build-test && mocha -t 120000 test-dist/index.js"
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/// <reference lib="es5" />
/// <reference lib="dom" />

import { AbortSignalLike, isNode } from "@azure/ms-rest-js";

/**
Expand Down Expand Up @@ -83,16 +86,14 @@ export class Aborter implements AbortSignalLike {
*
* @memberof Aborter
*/
public onabort?: ((ev?: Event) => any);
public onabort?: (ev?: Event) => any;

// tslint:disable-next-line:variable-name
private _aborted: boolean = false;
private timer?: any;
private readonly parent?: Aborter;
private readonly children: Aborter[] = []; // When child object calls dispose(), remove child from here
private readonly abortEventListeners: Array<
(this: AbortSignalLike, ev?: any) => any
> = [];
private readonly abortEventListeners: Array<(this: AbortSignalLike, ev?: any) => any> = [];
// Pipeline proxies need to use "abortSignal as Aborter" in order to access non AbortSignalLike methods
// immutable primitive types
private readonly key?: string;
Expand Down Expand Up @@ -164,10 +165,7 @@ export class Aborter implements AbortSignalLike {
* @returns {Aborter}
* @memberof Aborter
*/
public withValue(
key: string,
value?: string | number | boolean | null
): Aborter {
public withValue(key: string, value?: string | number | boolean | null): Aborter {
const childCancelContext = new Aborter(this, 0, key, value);
this.children.push(childCancelContext);
return childCancelContext;
Expand All @@ -184,11 +182,7 @@ export class Aborter implements AbortSignalLike {
* @memberof Aborter
*/
public getValue(key: string): string | number | boolean | null | undefined {
for (
let parent: Aborter | undefined = this;
parent;
parent = parent.parent
) {
for (let parent: Aborter | undefined = this; parent; parent = parent.parent) {
if (parent.key === key) {
return parent.value;
}
Expand Down Expand Up @@ -216,11 +210,11 @@ export class Aborter implements AbortSignalLike {
this.onabort.call(this);
}

this.abortEventListeners.forEach(listener => {
this.abortEventListeners.forEach((listener) => {
listener.call(this);
});

this.children.forEach(child => child.cancelByParent());
this.children.forEach((child) => child.cancelByParent());

this._aborted = true;
}
Expand Down
38 changes: 38 additions & 0 deletions sdk/core/aborter/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"compilerOptions": {
/* Basic Options */
"target": "es5" /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017','ES2018' or 'ESNEXT'. */,
"module": "es6" /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', or 'ESNext'. */,
"lib": [] /* lib dependencies are triple-slash directives in lib/index.ts */,
"declaration": true /* Generates corresponding '.d.ts' file. */,
"declarationMap": true /* Generates a sourcemap for each corresponding '.d.ts' file. */,
"sourceMap": true /* Generates corresponding '.map' file. */,

"outDir": "./dist-esm" /* Redirect output structure to the directory. */,
"stripInternal": true /* Do not emit declarations for code with @internal annotation*/,
"declarationDir": "./typings" /* Output directory for generated declaration files.*/,
"importHelpers": true /* Import emit helpers from 'tslib'. */,

/* Strict Type-Checking Options */
"strict": true /* Enable all strict type-checking options. */,
"noImplicitReturns": true /* Report error when not all code paths in function return a value. */,

/* Additional Checks */
"noUnusedLocals": true /* Report errors on unused locals. */,

/* Module Resolution Options */
"moduleResolution": "node" /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */,
"allowSyntheticDefaultImports": true /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */,
"esModuleInterop": true /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */,

/* Experimental Options */
"forceConsistentCasingInFileNames": true,

/* Other options */
"newLine": "LF" /* Use the specified end of line sequence to be used when emitting files: "crlf" (windows) or "lf" (unix).”*/,
"allowJs": false /* Don't allow JavaScript files to be compiled.*/
},
"compileOnSave": true,
"exclude": ["node_modules", "typings/**", "./samples/**/*.ts"],
"include": ["./src/**/*.ts", "./test/**/*.ts"]
}
1 change: 1 addition & 0 deletions sdk/storage/storage-blob/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"dependencies": {
"@azure/ms-rest-js": "^1.2.6",
"@azure/core-aborter": "^1.0.0",
"events": "^3.0.0",
"tslib": "^1.9.3"
},
Expand Down
Loading