karma-requirejs-esm-preprocessor 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +63 -0
  3. package/index.js +21 -0
  4. package/package.json +79 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Ferdinand Prantl
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # karma-requirejs-esm-preprocessor
2
+
3
+ [![Latest version](https://img.shields.io/npm/v/karma-requirejs-esm-preprocessor)
4
+ ![Dependency status](https://img.shields.io/librariesio/release/npm/karma-requirejs-esm-preprocessor)
5
+ ](https://www.npmjs.com/package/karma-requirejs-esm-preprocessor)
6
+
7
+ [Karma] preprocessor for converting ES modules to AMD in [RequireJS] projects. Uses [requirejs-esm-preprocessor].
8
+
9
+ ## Synopsis
10
+
11
+ ```js
12
+ module.exports = config => config.set({
13
+ preprocessors: {
14
+ 'src/**/*.js': ['requirejs-esm']
15
+ },
16
+ requirejsEsmPreprocessor: {
17
+ isScript: path => !path.includes('/test/'),
18
+ sourceMap: true
19
+ }
20
+ })
21
+ ```
22
+
23
+ ## Installation
24
+
25
+ This module can be installed in your project using [NPM], [PNPM] or [Yarn]. Make sure, that you use [Node.js] version 14 or newer.
26
+
27
+ ```sh
28
+ npm i -D karma-requirejs-esm-preprocessor
29
+ pnpm i -D karma-requirejs-esm-preprocessor
30
+ yarn add karma-requirejs-esm-preprocessor
31
+ ```
32
+
33
+ ## Configuration
34
+
35
+ ```ts
36
+ isScript(path: string): boolean
37
+ ```
38
+
39
+ Allows further filtering the files before passing them to the preprocessor. If the patterns are inconvenient to specify what files should be preprocessed, a simple pattern can be used to capture all files and the final filtering be done by `isScript` returning `true` only for the paths to files which need preprocessing. The default is `undefined` - no extra filtering.
40
+
41
+ ```ts
42
+ sourceMap: boolean
43
+ ```
44
+
45
+ Enables an inline source map in the preprocessed output to support debugging in the browser. The default is `true`.
46
+
47
+ ## Contributing
48
+
49
+ In lieu of a formal styleguide, take care to maintain the existing coding style. Lint and test your code.
50
+
51
+ ## License
52
+
53
+ Copyright (c) 2022 Ferdinand Prantl
54
+
55
+ Licensed under the MIT license.
56
+
57
+ [RequireJS]: http://requirejs.org/
58
+ [Karma]: http://karma-runner.github.io/
59
+ [requirejs-esm-preprocessor]: https://www.npmjs.com/package/requirejs-esm-preprocessor#readme
60
+ [Node.js]: http://nodejs.org/
61
+ [NPM]: https://www.npmjs.com/
62
+ [PNPM]: https://pnpm.io/
63
+ [Yarn]: https://yarnpkg.com/
package/index.js ADDED
@@ -0,0 +1,21 @@
1
+ const { preprocess } = require('requirejs-esm-preprocessor')
2
+
3
+ function createPreprocessor(args, config, helper) {
4
+ const { logLevel, LOG_DEBUG, LOG_DISABLE, requirejsEsmPreprocessor } = config
5
+ const defaults = { sourceMap: true }
6
+ const { isScript, sourceMap } = helper.merge(defaults, args, requirejsEsmPreprocessor || {})
7
+ const verbose = logLevel === LOG_DEBUG
8
+ const silent = logLevel === LOG_DISABLE
9
+
10
+ return (contents, file, done) => {
11
+ const { originalPath: path } = file
12
+ if (!isScript || isScript(path)) {
13
+ contents = preprocess({ path, contents, isScript, sourceMap, verbose, silent })
14
+ }
15
+ done(null, contents)
16
+ }
17
+ }
18
+
19
+ createPreprocessor.$inject = ['args', 'config', 'helper']
20
+
21
+ module.exports = { 'preprocessor:requirejs-esm': ['factory', createPreprocessor] }
package/package.json ADDED
@@ -0,0 +1,79 @@
1
+ {
2
+ "name": "karma-requirejs-esm-preprocessor",
3
+ "version": "1.0.0",
4
+ "description": "Karma preprocessor for converting ES modules to AMD in RequireJS projects.",
5
+ "author": "Ferdinand Prantl <prantlf@gmail.com>",
6
+ "license": "MIT",
7
+ "licenses": [
8
+ {
9
+ "type": "MIT",
10
+ "url": "https://github.com/prantlf/karma-requirejs-esm-preprocessor/blob/master/LICENSE"
11
+ }
12
+ ],
13
+ "homepage": "https://github.com/prantlf/karma-requirejs-esm-preprocessor#readme",
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/prantlf/karma-requirejs-esm-preprocessor.git"
17
+ },
18
+ "bugs": {
19
+ "url": "https://github.com/prantlf/karma-requirejs-esm-preprocessor/issues"
20
+ },
21
+ "engines": {
22
+ "node": ">=14"
23
+ },
24
+ "files": [
25
+ "index.js"
26
+ ],
27
+ "scripts": {
28
+ "lint": "eslint *.js",
29
+ "fix": "eslint *.js src test",
30
+ "check1": "karma start test/karma.conf1.js",
31
+ "check2": "karma start test/karma.conf2.js",
32
+ "check": "npm run check1 && npm run check2",
33
+ "cover": "c8 npm run check1 && c8 --no-clean npm run check2 && c8 report -r text -r lcov && c8 check-coverage --100",
34
+ "test": "npm run lint && npm run cover"
35
+ },
36
+ "c8": {
37
+ "reporter": []
38
+ },
39
+ "release": {
40
+ "plugins": [
41
+ "@semantic-release/commit-analyzer",
42
+ "@semantic-release/release-notes-generator",
43
+ "@semantic-release/changelog",
44
+ "@semantic-release/npm",
45
+ [
46
+ "@semantic-release/github",
47
+ {
48
+ "failComment": false
49
+ }
50
+ ],
51
+ "@semantic-release/git"
52
+ ]
53
+ },
54
+ "dependencies": {
55
+ "requirejs-esm-preprocessor": "^1.0.0"
56
+ },
57
+ "devDependencies": {
58
+ "@semantic-release/changelog": "^6.0.1",
59
+ "@semantic-release/git": "^10.0.1",
60
+ "c8": "^7.11.0",
61
+ "eslint": "^8.12.0",
62
+ "jasmine-core": "^4.0.1",
63
+ "karma": "^6.3.17",
64
+ "karma-brief-reporter": "^0.2.1",
65
+ "karma-chrome-launcher": "^3.1.1",
66
+ "karma-jasmine": "^4.0.2"
67
+ },
68
+ "keywords": [
69
+ "karma-preprocessor",
70
+ "karma-plugin",
71
+ "karma",
72
+ "preprocessor",
73
+ "plugin",
74
+ "requirejs",
75
+ "amd",
76
+ "esm",
77
+ "es6"
78
+ ]
79
+ }