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

Add support for building for different kind of loaders #325

Merged
merged 5 commits into from
Oct 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
1 change: 1 addition & 0 deletions .codacy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ exclude_paths:
- "third_party/**"
- "changelog.md"
- "CODE_OF_CONDUCT.md"
- "scripts/**"
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.DS_Store
node_modules/
package-lock.json
.vscode/
.vscode/
dist/
src/*.d.ts
4 changes: 0 additions & 4 deletions dist/README.md

This file was deleted.

8 changes: 0 additions & 8 deletions dist/html5-qrcode.min.js

This file was deleted.

34 changes: 26 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
{
"name": "html5-qrcode",
"version": "2.0.13",
"version": "2.1.0",
"description": "A cross platform HTML5 QR Code & bar code scanner",
"main": "dist/html5-qrcode.min.js",
"main": "./cjs/index.js",
"module": "./esm/index.js",
"typings": "./esm/index.d.ts",
"esnext": "./es2015/index.js",
"unpkg": "./html5-qrcode.min.js",
"scripts": {
"build-windows": "scripts\\build-windows.sh",
"build": "./scripts/build-default.sh",
"test": "./scripts/test.sh",
"lint-md": "remark ."
"lint-md": "remark .",
"clean": "rm -Rf ./lib/* ./build/* ./meta/bundlesize/* ./meta/coverage/* ./.rpt2_cache ./dist/* ./src/*.d.ts",
"prebuild": "npm run clean",
"postbuild": "cp -R ./third_party ./dist/third_party",
"build": "npm run build:es2015 && npm run build:esm && npm run build:esnext && npm run build:cjs && npm run build:umd && npm run build:typing && npm run build:copy",
"build:es2015": "tsc --build tsconfig.lib-es2015.json",
"build:esm": "tsc --build tsconfig.lib-esm.json",
"build:esnext": "tsc --build tsconfig.lib-esm.json",
"build:cjs": "tsc --build tsconfig.lib-cjs.json",
"build:typing": "tsc --emitDeclarationOnly --outDir ./dist",
"build:umd": "./scripts/build-webpack.sh",
"build:copy": "cp README.md dist && cp package.json dist && cp LICENSE dist",
"release": "npm run build && cd dist && npm publish"
},
"repository": {
"type": "git",
Expand All @@ -18,7 +33,10 @@
"qrcode",
"html",
"camera",
"scanner"
"scanner",
"barcode",
"barcode 1d",
"barcode 2d"
],
"author": "[email protected]",
"license": "Apache-2.0",
Expand Down Expand Up @@ -51,7 +69,7 @@
"remark-preset-lint-recommended"
]
},
"files": [
"dist/*"
]
"publishConfig": {
"access": "public"
}
}
12 changes: 12 additions & 0 deletions scripts/build-webpack.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#!/bin/bash
## Build Script
echo 'Initiating webpack build sequence.'

webpack

## Script copied to dist/html5-qrcode.min.js
## Fork content of 'webpack_append_data.js' to final js file to
## make classes global to be backwards compatible.
cat scripts/webpack_append_data.js >> dist/html5-qrcode.min.js

echo 'Webpack building done.'
6 changes: 6 additions & 0 deletions scripts/webpack_append_data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** Append the libary components to globals for backwards compatibility. */
if (window && !Html5QrcodeScanner) {
var Html5QrcodeScanner = window.__Html5QrcodeLibrary__.Html5QrcodeScanner;
var Html5Qrcode = window.__Html5QrcodeLibrary__.Html5Qrcode;
var Html5QrcodeSupportedFormats = window.__Html5QrcodeLibrary__.Html5QrcodeSupportedFormats
}
31 changes: 0 additions & 31 deletions src/html5-qrcode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,37 +396,6 @@ export class Html5Qrcode {
.catch((error) => {
reject(Html5QrcodeStrings.errorGettingUserMedia(error));
});
} else if (navigator.getUserMedia) {
mebjas marked this conversation as resolved.
Show resolved Hide resolved
if (typeof cameraIdOrConfig != "string") {
// TODO(mebjas): Make errors more concrete and categorizable.
throw Html5QrcodeStrings.onlyDeviceSupportedError();
}
const getCameraConfig: MediaStreamConstraints = {
video: videoConstraints
};
navigator.getUserMedia(getCameraConfig,
(stream: MediaStream) => {
$this.onMediaStreamReceived(
stream,
internalConfig,
areVideoConstraintsEnabled,
rootElementWidth,
qrCodeSuccessCallback,
qrCodeErrorCallback!)
.then((_) => {
$this.isScanning = true;
resolve(/* Void */ null);

})
.catch((error) => {
reject(
Html5QrcodeStrings.errorGettingUserMedia(
error));

});
}, (error: any) => {
reject(Html5QrcodeStrings.errorGettingUserMedia(error));
});
} else {
reject(Html5QrcodeStrings.cameraStreamingNotSupported());
}
Expand Down
5 changes: 2 additions & 3 deletions src/zxing-html5-qrcode-decoder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* http://www.denso-wave.com/qrcode/faqpatent-e.html
*/

import * as ZXing from "../third_party/zxing-js.umd";

import {
QrcodeResult,
QrcodeResultFormat,
Expand All @@ -18,9 +20,6 @@ import {
QrcodeDecoderAsync
} from "./core";

// Ambient tag to refer to ZXing library.
declare const ZXing: any;

/**
* ZXing based Code decoder.
*/
Expand Down
42 changes: 42 additions & 0 deletions third_party/zxing-js.umd.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import * as ZXing from "./zxing-js.umd";

declare class HTMLCanvasElementLuminanceSource {
constructor(canvas: HTMLCanvasElement);
}

declare class HybridBinarizer {
constructor(luminanceSource: HTMLCanvasElementLuminanceSource);
}

declare class BinaryBitmap {
constructor(binarizer: HybridBinarizer);
}

declare class MultiFormatReader {
constructor(verbosity: boolean, b: any);
decode(binaryBitmap: BinaryBitmap): any;
}

export declare enum DecodeHintType {
POSSIBLE_FORMATS = 2
}

export declare enum BarcodeFormat {
AZTEC = 0,
CODABAR = 1,
CODE_39 = 2,
CODE_93 = 3,
CODE_128 = 4,
DATA_MATRIX = 5,
EAN_8 = 6,
EAN_13 = 7,
ITF = 8,
MAXICODE = 9,
PDF_417 = 10,
QR_CODE = 11,
RSS_14 = 12,
RSS_EXPANDED = 13,
UPC_A = 14,
UPC_E = 15,
UPC_EAN_EXTENSION = 16
}
18 changes: 15 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
"target": "es5",
"module": "ES2015",
"sourceMap": true,
"moduleResolution": "classic",
"moduleResolution": "Node",
"declaration": true,
"lib": [
"es7",
"dom"
Expand All @@ -17,9 +18,20 @@
"experimentalDecorators": true,
"removeComments": true,
"preserveConstEnums": true,
"noImplicitAny": true
"noImplicitAny": true,

// Allow javascript source to be built
"allowJs": true
},
"files": [
"src/index.ts"
]
],
"paths": {
"@scanapp/html5-qrcode": [
"./dist"
],
"@scanapp/html5-qrcode/*": [
"./dist/*"
]
}
}
8 changes: 8 additions & 0 deletions tsconfig.lib-cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "commonjs",
"target": "es5",
"outDir": "dist/cjs"
}
}
8 changes: 8 additions & 0 deletions tsconfig.lib-es2015.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "es2015",
"target": "es2015",
"outDir": "dist/es2015"
}
}
8 changes: 8 additions & 0 deletions tsconfig.lib-esm.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "es2015",
"target": "es5",
"outDir": "dist/esm"
}
}
8 changes: 8 additions & 0 deletions tsconfig.lib-esnext.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "esnext",
"target": "esnext",
"outDir": "dist/esnext"
}
}
20 changes: 20 additions & 0 deletions tsconfig.test.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"target": "es6",
"module": "commonjs",
"moduleResolution": "node",
"lib": [
"es7",
"dom"
],
"outDir": "output/tests"
},
"include": [
"test/**/*.ts"
],
"exclude": [
"node_modules",
"src/core"
]
}
6 changes: 3 additions & 3 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ module.exports = {
// output bundles (location)
output: {
path: path.resolve( __dirname, "dist" ),
filename: "html5-qrcode.library.min.js",
library: "_",
filename: "html5-qrcode.min.js",
library: "__Html5QrcodeLibrary__",
mebjas marked this conversation as resolved.
Show resolved Hide resolved
},
// file resolutions
resolve: {
extensions: [ ".ts" ],
extensions: [ ".ts", ".js" ],
},
target: "web",
module: {
Expand Down