@modern-js/plugin-module-import 2.7.0-beta.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Modern.js
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,38 @@
1
+ # @modern-js/plugin-module-import
2
+
3
+ The polyfill plugin of Modern.js Module Tools.
4
+
5
+ A Library author don't want to "pollute" the global scope with the polyfills you are loading. This plugin injects imports to polyfills for unsupported features which are used in your code, without attaching the polyfills to the global scope but importing them as normal functions.
6
+
7
+ **Note: It will not transform syntax by targets**
8
+
9
+ ## Usage
10
+
11
+ ```ts
12
+ import { defineConfig } from '@modern-js/module-tools';
13
+ import moduleImport from '@modern-js/plugin-module-import';
14
+
15
+ export default defineConfig({
16
+ plugins: [moduleImport({
17
+ pluginImport: [
18
+ {
19
+ libraryName: 'antd',
20
+ style: 'css',
21
+ },
22
+ ],
23
+ })],
24
+ });
25
+ ```
26
+
27
+ ## Documentation
28
+
29
+ - [English Documentation](https://modernjs.dev/module-tools/en)
30
+ - [中文文档](https://modernjs.dev/module-tools/)
31
+
32
+ ## Contributing
33
+
34
+ Please read the [Contributing Guide](https://github.com/modern-js-dev/modern.js/blob/main/CONTRIBUTING.md).
35
+
36
+ ## License
37
+
38
+ Modern.js is [MIT licensed](https://github.com/modern-js-dev/modern.js/blob/main/LICENSE).
@@ -0,0 +1,8 @@
1
+ import { CliPlugin, ModuleTools } from '@modern-js/module-tools';
2
+ import { ImportItem } from '@modern-js/libuild-plugin-swc';
3
+
4
+ declare const _default: (options: {
5
+ pluginImport?: ImportItem[];
6
+ }) => CliPlugin<ModuleTools>;
7
+
8
+ export { _default as default };
package/dist/index.js ADDED
@@ -0,0 +1,87 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+ var __async = (__this, __arguments, generator) => {
29
+ return new Promise((resolve, reject) => {
30
+ var fulfilled = (value) => {
31
+ try {
32
+ step(generator.next(value));
33
+ } catch (e) {
34
+ reject(e);
35
+ }
36
+ };
37
+ var rejected = (value) => {
38
+ try {
39
+ step(generator.throw(value));
40
+ } catch (e) {
41
+ reject(e);
42
+ }
43
+ };
44
+ var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
45
+ step((generator = generator.apply(__this, __arguments)).next());
46
+ });
47
+ };
48
+
49
+ // src/index.ts
50
+ var src_exports = {};
51
+ __export(src_exports, {
52
+ default: () => src_default
53
+ });
54
+ module.exports = __toCommonJS(src_exports);
55
+ var src_default = (options) => ({
56
+ name: "@modern-js/plugin-module-import",
57
+ setup: () => ({
58
+ modifyLibuild(config, next) {
59
+ return __async(this, null, function* () {
60
+ var _a2, _b;
61
+ if (!options.pluginImport || options.pluginImport.length === 0) {
62
+ return next(config);
63
+ }
64
+ const { transformPlugin } = yield import("@modern-js/libuild-plugin-swc");
65
+ (_b = config.plugins) == null ? void 0 : _b.push(
66
+ transformPlugin({
67
+ jsc: {
68
+ parser: {
69
+ syntax: "ecmascript",
70
+ jsx: true
71
+ },
72
+ target: "es2022"
73
+ },
74
+ extensions: {
75
+ pluginImport: (_a2 = options.pluginImport) != null ? _a2 : []
76
+ }
77
+ })
78
+ );
79
+ return next(config);
80
+ });
81
+ }
82
+ })
83
+ });
84
+ // Annotate the CommonJS export names for ESM import in node:
85
+ 0 && (module.exports = {});
86
+
87
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,IAAO,cAAQ,CAAC,aAEe;AAAA,EAC7B,MAAM;AAAA,EACN,OAAO,OAAO;AAAA,IACN,cAAc,QAAQ,MAAM;AAAA;AARtC;AASM,YAAI,CAAC,QAAQ,gBAAgB,QAAQ,aAAa,WAAW,GAAG;AAC9D,iBAAO,KAAK,MAAM;AAAA,QACpB;AAEA,cAAM,EAAE,gBAAgB,IAAI,MAAM,OAAO,+BAA+B;AACxE,qBAAO,YAAP,mBAAgB;AAAA,UACd,gBAAgB;AAAA,YACd,KAAK;AAAA,cACH,QAAQ;AAAA,gBACN,QAAQ;AAAA,gBACR,KAAK;AAAA,cACP;AAAA,cACA,QAAQ;AAAA,YACV;AAAA,YACA,YAAY;AAAA,cACV,eAAcA,cAAQ,iBAAR,aAAwB,CAAC;AAAA,YACzC;AAAA,UACF,CAAC;AAAA;AAGH,eAAO,KAAK,MAAM;AAAA,MACpB;AAAA;AAAA,EACF;AACF;","names":["_a"],"sources":["../src/index.ts"],"sourcesContent":["import type { CliPlugin, ModuleTools } from '@modern-js/module-tools';\nimport type { ImportItem } from '@modern-js/libuild-plugin-swc';\n\nexport default (options: {\n pluginImport?: ImportItem[];\n}): CliPlugin<ModuleTools> => ({\n name: '@modern-js/plugin-module-import',\n setup: () => ({\n async modifyLibuild(config, next) {\n if (!options.pluginImport || options.pluginImport.length === 0) {\n return next(config);\n }\n\n const { transformPlugin } = await import('@modern-js/libuild-plugin-swc');\n config.plugins?.push(\n transformPlugin({\n jsc: {\n parser: {\n syntax: 'ecmascript',\n jsx: true,\n },\n target: 'es2022',\n },\n extensions: {\n pluginImport: options.pluginImport ?? [],\n },\n }),\n );\n\n return next(config);\n },\n }),\n});\n"]}
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@modern-js/plugin-module-import",
3
+ "description": "The import plugin of Modern.js Module Tools.",
4
+ "homepage": "https://modernjs.dev/module-tools",
5
+ "bugs": "https://github.com/modern-js-dev/modern.js/issues",
6
+ "repository": "modern-js-dev/modern.js",
7
+ "license": "MIT",
8
+ "keywords": [
9
+ "react",
10
+ "framework",
11
+ "modern",
12
+ "modern.js"
13
+ ],
14
+ "version": "2.7.0-beta.0",
15
+ "types": "./dist/types/index.d.ts",
16
+ "main": "./dist/index.js",
17
+ "dependencies": {
18
+ "@modern-js/libuild-plugin-swc": "~0.11.0"
19
+ },
20
+ "devDependencies": {
21
+ "@types/jest": "^27",
22
+ "@types/node": "^14",
23
+ "typescript": "^4",
24
+ "jest": "^27",
25
+ "@modern-js/libuild": "~0.11.0",
26
+ "@scripts/build": "2.7.0",
27
+ "@modern-js/module-tools": "2.7.0",
28
+ "@scripts/jest-config": "2.7.0"
29
+ },
30
+ "peerDependencies": {
31
+ "@modern-js/module-tools": "2.7.0"
32
+ },
33
+ "peerDependenciesMeta": {
34
+ "@modern-js/module-tools": {
35
+ "optional": true
36
+ }
37
+ },
38
+ "publishConfig": {
39
+ "registry": "https://registry.npmjs.org/",
40
+ "access": "public"
41
+ },
42
+ "scripts": {
43
+ "dev": "mdn build --watch",
44
+ "build": "mdn build",
45
+ "test": "jest --passWithNoTests"
46
+ }
47
+ }