Skip to content

Commit

Permalink
Merge pull request #32 from UmamiAppearance/v0.4.0
Browse files Browse the repository at this point in the history
V0.4.0
  • Loading branch information
UmamiAppearance authored Jan 11, 2023
2 parents 824ba20 + 64f6b35 commit e339b8d
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 117 deletions.
301 changes: 203 additions & 98 deletions README.md

Large diffs are not rendered by default.

20 changes: 17 additions & 3 deletions cjs/rollup-plugin-import-manager.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ const showDiff = (filename, source, code, diffOption) => {
/**
* [rollup-plugin-import-manager]{@link https://github.com/UmamiAppearance/rollup-plugin-import-manager}
*
* @version 0.3.7
* @version 0.4.0
* @author UmamiAppearance [[email protected]]
* @license MIT
*/
Expand Down Expand Up @@ -184,7 +184,7 @@ const importManager = (options={}) => {

const warnings = typeof options.warnings === "undefined" ? true : bool(options.warnings);

const manager = new importManager$1.ImportManager(source, id, warnSpamProtection, warnings);
const manager = new importManager$1.ImportManager(source, id, warnSpamProtection, warnings, this);

if (!("units" in options) || "debug" in options) {
if (showObjects(options.debug)) {
Expand Down Expand Up @@ -319,7 +319,21 @@ const importManager = (options={}) => {
}

else {
const type = unitSection.type === "cjs" ? "cjs" : "es6";
// default is es6
let type = "es6";

// overwrite this if set by the config
if (unitSection.type) {
type = unitSection.type;
}

// if type is dynamic change to es6 if is6 imports
// are found (as dynamic imports can be wildly spread)

if (type === "dynamic" && manager.imports.es6.length) {
type = "es6";
}

manager.insertStatement(codeSnippet, unitSection.insert, type);
}

Expand Down
2 changes: 1 addition & 1 deletion cjs/rollup-plugin-import-manager.cjs.map

Large diffs are not rendered by default.

18 changes: 9 additions & 9 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 5 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rollup-plugin-import-manager",
"version": "0.3.7",
"version": "0.4.0",
"description": "A rollup plugin to add, modify, and remove imports (cjs/es6/dynamic)",
"main": "./cjs/rollup-plugin-import-manager.cjs",
"module": "./src/index.js",
Expand Down Expand Up @@ -29,10 +29,13 @@
"add",
"cjs",
"es6",
"delete",
"dynamic",
"import",
"import-manager",
"modules",
"remove",
"replace",
"rollup",
"rollup-plugin",
"rollup-plugin-import-manager",
Expand All @@ -42,7 +45,7 @@
"@rollup/pluginutils": "^5.0.2",
"colorette": "^2.0.19",
"diff": "^5.1.0",
"import-manager": "^0.1.7"
"import-manager": "^0.2.0"
},
"devDependencies": {
"ava": "^5.1.0",
Expand Down
20 changes: 17 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
* [rollup-plugin-import-manager]{@link https://github.com/UmamiAppearance/rollup-plugin-import-manager}
*
* @version 0.3.7
* @version 0.4.0
* @author UmamiAppearance [[email protected]]
* @license MIT
*/
Expand Down Expand Up @@ -61,7 +61,7 @@ const importManager = (options={}) => {

const warnings = typeof options.warnings === "undefined" ? true : bool(options.warnings);

const manager = new ImportManager(source, id, warnSpamProtection, warnings);
const manager = new ImportManager(source, id, warnSpamProtection, warnings, this);

if (!("units" in options) || "debug" in options) {
if (showObjects(options.debug)) {
Expand Down Expand Up @@ -196,7 +196,21 @@ const importManager = (options={}) => {
}

else {
const type = unitSection.type === "cjs" ? "cjs" : "es6";
// default is es6
let type = "es6";

// overwrite this if set by the config
if (unitSection.type) {
type = unitSection.type;
}

// if type is dynamic change to es6 if is6 imports
// are found (as dynamic imports can be wildly spread)

if (type === "dynamic" && manager.imports.es6.length) {
type = "es6";
}

manager.insertStatement(codeSnippet, unitSection.insert, type);
}

Expand Down
3 changes: 2 additions & 1 deletion tests/dynamic.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,8 @@ test("creating an import statement", async (t) => {
file: "**/hi.dynamic.js",
createModule: "./lib/create.js",
type: "dynamic",
const: "create"
const: "create",
insert: "top"
}
})
]
Expand Down

0 comments on commit e339b8d

Please sign in to comment.