From f28e9815ebd1fd3507bba20741b9de6bc49e3b63 Mon Sep 17 00:00:00 2001 From: FUJI Goro Date: Sun, 4 Oct 2020 23:25:46 +0900 Subject: [PATCH 1/8] doc: explain es5+esm --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 900e193f..4373cbae 100644 --- a/README.md +++ b/README.md @@ -521,11 +521,11 @@ Note that `Buffer.from()` for `JSON.stringify()` is necessary to emulate I/O whe The NPM package distributed in npmjs.com includes both ES2015+ and ES5 files: -* `dist/` is compiled into ES2015+ -* `dist.es5+umd/` is compiled into ES5 and bundled to singile file +* `dist/` is compiled into ES2015+, provided for NodeJS v10 or later +* `dist.es5+umd/` is compiled into ES5 with UMD-style single file * `dist.es5+umd/msgpack.min.js` - the default, minified file (UMD) * `dist.es5+umd/msgpack.js` - an optional, non-minified file (UMD) -* `dist.es5+esm/` is compiled into ES5 and placed as ES modules +* `dist.es5+esm/` is compiled into ES5 and placed as ES modules, provided for webpack-like bundlers, not NodeJS If you use NodeJS and/or webpack, their module resolvers use the suitable one automatically. From 15a136fb0b2a14a2e2fa3c9d9edaecdbaa574652 Mon Sep 17 00:00:00 2001 From: FUJI Goro Date: Sat, 10 Oct 2020 23:27:17 +0900 Subject: [PATCH 2/8] add example for webpack --- README.md | 6 +- example/webpack-example/.gitignore | 1 + example/webpack-example/README.md | 11 ++++ example/webpack-example/index.ts | 4 ++ example/webpack-example/package.json | 22 +++++++ example/webpack-example/tsconfig.json | 71 +++++++++++++++++++++++ example/webpack-example/webpack.config.ts | 61 +++++++++++++++++++ 7 files changed, 173 insertions(+), 3 deletions(-) create mode 100644 example/webpack-example/.gitignore create mode 100644 example/webpack-example/README.md create mode 100644 example/webpack-example/index.ts create mode 100644 example/webpack-example/package.json create mode 100644 example/webpack-example/tsconfig.json create mode 100644 example/webpack-example/webpack.config.ts diff --git a/README.md b/README.md index 900e193f..4373cbae 100644 --- a/README.md +++ b/README.md @@ -521,11 +521,11 @@ Note that `Buffer.from()` for `JSON.stringify()` is necessary to emulate I/O whe The NPM package distributed in npmjs.com includes both ES2015+ and ES5 files: -* `dist/` is compiled into ES2015+ -* `dist.es5+umd/` is compiled into ES5 and bundled to singile file +* `dist/` is compiled into ES2015+, provided for NodeJS v10 or later +* `dist.es5+umd/` is compiled into ES5 with UMD-style single file * `dist.es5+umd/msgpack.min.js` - the default, minified file (UMD) * `dist.es5+umd/msgpack.js` - an optional, non-minified file (UMD) -* `dist.es5+esm/` is compiled into ES5 and placed as ES modules +* `dist.es5+esm/` is compiled into ES5 and placed as ES modules, provided for webpack-like bundlers, not NodeJS If you use NodeJS and/or webpack, their module resolvers use the suitable one automatically. diff --git a/example/webpack-example/.gitignore b/example/webpack-example/.gitignore new file mode 100644 index 00000000..d8b83df9 --- /dev/null +++ b/example/webpack-example/.gitignore @@ -0,0 +1 @@ +package-lock.json diff --git a/example/webpack-example/README.md b/example/webpack-example/README.md new file mode 100644 index 00000000..a2ae2f5a --- /dev/null +++ b/example/webpack-example/README.md @@ -0,0 +1,11 @@ +# Webpack Example for @msgpack/msgpack + +This example demonstrates tree-shaking with webpack. + +## Usage + +```shell +npm install +npx webpack +ls -lh dist/ +``` diff --git a/example/webpack-example/index.ts b/example/webpack-example/index.ts new file mode 100644 index 00000000..8b1c01c9 --- /dev/null +++ b/example/webpack-example/index.ts @@ -0,0 +1,4 @@ +import { encode } from "@msgpack/msgpack"; + +console.log(encode(null)); + diff --git a/example/webpack-example/package.json b/example/webpack-example/package.json new file mode 100644 index 00000000..6c891bd6 --- /dev/null +++ b/example/webpack-example/package.json @@ -0,0 +1,22 @@ +{ + "name": "webpack-example", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "author": "", + "license": "ISC", + "dependencies": { + "@msgpack/msgpack": "../../" + }, + "devDependencies": { + "lodash": "^4.17.20", + "ts-loader": "^8.0.4", + "ts-node": "^9.0.0", + "typescript": "^4.0.3", + "webpack": "^4.44.2", + "webpack-cli": "^3.3.12" + } +} diff --git a/example/webpack-example/tsconfig.json b/example/webpack-example/tsconfig.json new file mode 100644 index 00000000..21cacb8f --- /dev/null +++ b/example/webpack-example/tsconfig.json @@ -0,0 +1,71 @@ +{ + "compilerOptions": { + /* Visit https://aka.ms/tsconfig.json to read more about this file */ + + /* Basic Options */ + // "incremental": true, /* Enable incremental compilation */ + "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ + "module": "es2020", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ + // "lib": [], /* Specify library files to be included in the compilation. */ + // "allowJs": true, /* Allow javascript files to be compiled. */ + // "checkJs": true, /* Report errors in .js files. */ + // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ + // "declaration": true, /* Generates corresponding '.d.ts' file. */ + // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ + // "sourceMap": true, /* Generates corresponding '.map' file. */ + // "outFile": "./", /* Concatenate and emit output to single file. */ + // "outDir": "./", /* Redirect output structure to the directory. */ + // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ + // "composite": true, /* Enable project compilation */ + // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ + // "removeComments": true, /* Do not emit comments to output. */ + // "noEmit": true, /* Do not emit outputs. */ + // "importHelpers": true, /* Import emit helpers from 'tslib'. */ + // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ + // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ + + /* Strict Type-Checking Options */ + "strict": true, /* Enable all strict type-checking options. */ + // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ + // "strictNullChecks": true, /* Enable strict null checks. */ + // "strictFunctionTypes": true, /* Enable strict checking of function types. */ + // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ + // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ + // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ + // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ + + /* Additional Checks */ + // "noUnusedLocals": true, /* Report errors on unused locals. */ + // "noUnusedParameters": true, /* Report errors on unused parameters. */ + // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ + // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ + + /* Module Resolution Options */ + "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ + "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ + "paths": { + "@msgpack/msgpack": ["../../"] + }, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ + // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ + // "typeRoots": [], /* List of folders to include type definitions from. */ + // "types": [], /* Type declaration files to be included in compilation. */ + // "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'. */ + // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ + // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ + + /* Source Map Options */ + // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ + // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ + // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ + // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ + + /* Experimental Options */ + // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ + // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ + + /* Advanced Options */ + "skipLibCheck": true, /* Skip type checking of declaration files. */ + "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ + } +} diff --git a/example/webpack-example/webpack.config.ts b/example/webpack-example/webpack.config.ts new file mode 100644 index 00000000..3d22690c --- /dev/null +++ b/example/webpack-example/webpack.config.ts @@ -0,0 +1,61 @@ +const path = require("path"); +const webpack = require("webpack"); +const _ = require("lodash"); + +const config = { + mode: "production", + + entry: "./index.ts", + output: { + path: path.resolve(__dirname, "dist"), + filename: undefined, // will be set later + }, + resolve: { + extensions: [".ts", ".tsx", ".mjs", ".js", ".json", ".wasm"], + }, + module: { + rules: [ + { + test: /\.tsx?$/, + loader: "ts-loader", + options: { + configFile: "tsconfig.json", + }, + }, + ], + }, + + plugins: [ + new webpack.DefinePlugin({ + // eslint-disable-next-line @typescript-eslint/naming-convention + "process.env.TEXT_ENCODING": "undefined", + // eslint-disable-next-line @typescript-eslint/naming-convention + "process.env.TEXT_DECODER": "undefined", + }), + ], + + optimization: { + noEmitOnErrors: true, + minimize: false, + }, + + // We don't need NodeJS stuff on browsers! + // https://webpack.js.org/configuration/node/ + node: false, + + devtool: "source-map", +}; + +module.exports = [ + ((config) => { + config.output.filename = "bundle.min.js"; + config.optimization.minimize = true; + return config; + })(_.cloneDeep(config)), + + ((config) => { + config.output.filename = "bundle.js"; + config.optimization.minimize = false; + return config; + })(_.cloneDeep(config)), +]; From 7f3416f4756847640d0e3aa13c1c979a49003f86 Mon Sep 17 00:00:00 2001 From: FUJI Goro Date: Sat, 10 Oct 2020 23:28:03 +0900 Subject: [PATCH 3/8] remove "browser" field not to be used by webpak --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 567fbc3b..86955259 100644 --- a/package.json +++ b/package.json @@ -5,8 +5,9 @@ "author": "The MessagePack community", "license": "ISC", "main": "./dist/index.js", - "browser": "./dist.es5+umd/msgpack.min.js", "module": "./dist.es5+esm/index.js", + "cdn": "./dist.es5+umd/msgpack.min.js", + "unpkg": "./dist.es5+umd/msgpack.min.js", "types": "./dist/index.d.ts", "sideEffects": false, "scripts": { From 138ace7ef168fbe801019409f4d3151640d0f1ca Mon Sep 17 00:00:00 2001 From: FUJI Goro Date: Sat, 10 Oct 2020 23:46:22 +0900 Subject: [PATCH 4/8] pin platform version for iOS/Android, etc --- sauceLabs.ts | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/sauceLabs.ts b/sauceLabs.ts index 4d582e4a..a0c2689a 100644 --- a/sauceLabs.ts +++ b/sauceLabs.ts @@ -48,8 +48,7 @@ export const sauceLaunchers: Record = { base: "SauceLabs", browserName: "Safari", version: "latest", - // "macOS 10.14" is unstable for now - platform: "macOS 10.13", + platform: "macOS 10.15", }, slEdge: { base: "SauceLabs", @@ -68,15 +67,15 @@ export const sauceLaunchers: Record = { base: "SauceLabs", browserName: "Safari", platformName: "iOS", - platformVersion: "latest", - deviceName: "iPhone X Simulator", + platformVersion: "13.4", + deviceName: "iPhone Simulator", }, slAndroid: { base: "SauceLabs", browserName: "Chrome", platformName: "Android", - platformVersion: "latest", - deviceName: "Android Emulator", + platformVersion: "11.0", + deviceName: "Android GoogleAPI Emulator", }, }; From 4d9949d0f1cb0110cbfadd467aad2c8941f43511 Mon Sep 17 00:00:00 2001 From: FUJI Goro Date: Sun, 11 Oct 2020 00:01:44 +0900 Subject: [PATCH 5/8] add deviceOrientation for SauceLabs --- sauceLabs.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sauceLabs.ts b/sauceLabs.ts index a0c2689a..86518703 100644 --- a/sauceLabs.ts +++ b/sauceLabs.ts @@ -11,6 +11,7 @@ export type SauceLauncher = { platform?: string; // for mobile + deviceOrientation?: string, deviceName?: string; appiumVersion?: string; platformName?: string; @@ -68,6 +69,7 @@ export const sauceLaunchers: Record = { browserName: "Safari", platformName: "iOS", platformVersion: "13.4", + deviceOrientation: "portrait", deviceName: "iPhone Simulator", }, @@ -76,6 +78,7 @@ export const sauceLaunchers: Record = { browserName: "Chrome", platformName: "Android", platformVersion: "11.0", + deviceOrientation: "portrait", deviceName: "Android GoogleAPI Emulator", }, }; From 1987b9296a6a7a1f2dfca25b2f3158855090d85a Mon Sep 17 00:00:00 2001 From: FUJI Goro Date: Sun, 11 Oct 2020 00:18:58 +0900 Subject: [PATCH 6/8] tweaks --- sauceLabs.ts | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/sauceLabs.ts b/sauceLabs.ts index 86518703..e4fe6ce3 100644 --- a/sauceLabs.ts +++ b/sauceLabs.ts @@ -5,16 +5,15 @@ const IS_LOCAL = !process.env.TRAVIS_BUILD_NUMBER; export type SauceLauncher = { base: "SauceLabs"; browserName: string; + platformName?: string; // for PC - version?: string; - platform?: string; + browserVersion?: string; // for mobile deviceOrientation?: string, deviceName?: string; appiumVersion?: string; - platformName?: string; platformVersion?: string; }; @@ -36,32 +35,32 @@ export const sauceLaunchers: Record = { slChrome: { base: "SauceLabs", browserName: "chrome", - version: "latest", - platform: "Windows 10", + browserVersion: "latest", + platformName: "Windows 10", }, slFirefox: { base: "SauceLabs", browserName: "Firefox", - version: "latest", - platform: "Windows 10", + browserVersion: "latest", + platformName: "Windows 10", }, slSafari: { base: "SauceLabs", browserName: "Safari", - version: "latest", - platform: "macOS 10.15", + browserVersion: "latest", + platformName: "macOS 10.15", }, slEdge: { base: "SauceLabs", browserName: "MicrosoftEdge", - version: "latest", - platform: "Windows 10", + browserVersion: "latest", + platformName: "Windows 10", }, slIE: { base: "SauceLabs", browserName: "Internet Explorer", - version: "latest", - platform: "Windows 10", + browserVersion: "latest", + platformName: "Windows 8", }, slIos: { @@ -69,7 +68,6 @@ export const sauceLaunchers: Record = { browserName: "Safari", platformName: "iOS", platformVersion: "13.4", - deviceOrientation: "portrait", deviceName: "iPhone Simulator", }, @@ -78,7 +76,6 @@ export const sauceLaunchers: Record = { browserName: "Chrome", platformName: "Android", platformVersion: "11.0", - deviceOrientation: "portrait", deviceName: "Android GoogleAPI Emulator", }, }; From dfce3b6b8a85d2b2272b50bafa272bfd9684bd9b Mon Sep 17 00:00:00 2001 From: FUJI Goro Date: Sun, 11 Oct 2020 00:43:02 +0900 Subject: [PATCH 7/8] changes for 2.2.1 --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4d6350bb..2a614fd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ This is the revision history of @msgpack/msgpack +## v2.2.1 2020/10/11 + +https://github.com/msgpack/msgpack-javascript/compare/v2.2.0...v2.2.1 + +* Fix `package.json` for webpack to use `module` field + ## v2.2.0 2020/10/04 https://github.com/msgpack/msgpack-javascript/compare/v2.1.1...v2.2.0 From 1d5d519d2a2d76af1ec89cce48b1a9d38c8e3500 Mon Sep 17 00:00:00 2001 From: FUJI Goro Date: Sun, 11 Oct 2020 00:43:11 +0900 Subject: [PATCH 8/8] 2.2.1 --- package-lock.json | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/package-lock.json b/package-lock.json index 13bac5bf..1e3c8850 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@msgpack/msgpack", - "version": "2.2.0", + "version": "2.2.1", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 86955259..2160bd38 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@msgpack/msgpack", - "version": "2.2.0", + "version": "2.2.1", "description": "MessagePack for JavaScript/ECMA-262", "author": "The MessagePack community", "license": "ISC",