Skip to content

Commit 0cf28e6

Browse files
author
Martynas Žilinskas
authored
Merge pull request #79 from reactway/dev
v3.0.2
2 parents 8de2feb + 4629f03 commit 0cf28e6

9 files changed

Lines changed: 70 additions & 14 deletions

File tree

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,15 @@ Bundles all SCSS imports into a single file recursively.
1414

1515
### Who uses `scss-bundle`
1616

17-
A few of the projects who use the package:
17+
#### Projects
1818

1919
- [Angular/material2](https://github.com/angular/material2)
2020
- [Grassy](https://github.com/lazarljubenovic/grassy)
2121

22+
#### Community plugins
23+
24+
- [rollup-plugin-bundle-scss](https://github.com/weizhenye/rollup-plugin-bundle-scss)
25+
2226
## Get started
2327

2428
If you want to use `scss-bundle` globally

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "scss-bundle",
3-
"version": "3.0.1",
3+
"version": "3.0.2",
44
"description": "Bundling SCSS files to one bundled file.",
55
"main": "dist/index.js",
66
"types": "dist/index.d.ts",

src/bundler.ts

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -135,22 +135,22 @@ export class Bundler {
135135
found: false,
136136
ignored: imp.ignored
137137
};
138-
} else if (this.fileRegistry[imp.fullPath] == null) {
138+
} else if (this.usedImports[imp.fullPath] == null) {
139+
// Add it to used imports
140+
this.usedImports[imp.fullPath] = 1;
141+
139142
// If file is not yet in the registry
140143
// Read
141-
const impContent = await fs.readFile(imp.fullPath, "utf-8");
144+
const impContent = this.fileRegistry[imp.fullPath] == null
145+
? await fs.readFile(imp.fullPath, "utf-8")
146+
: this.fileRegistry[imp.fullPath] as string;
142147

143148
// and bundle it
144149
const bundledImport = await this._bundle(imp.fullPath, impContent, dedupeFiles, includePaths, ignoredImports);
145150

146151
// Then add its bundled content to the registry
147152
this.fileRegistry[imp.fullPath] = bundledImport.bundledContent;
148153

149-
// Add it to used imports, if it's not there
150-
if (this.usedImports != null && this.usedImports[imp.fullPath] == null) {
151-
this.usedImports[imp.fullPath] = 1;
152-
}
153-
154154
// And whole BundleResult to current imports
155155
currentImport = bundledImport;
156156
} else {
@@ -236,6 +236,11 @@ export class Bundler {
236236
}
237237

238238
private async resolveImport(importData: ImportData, includePaths: string[]): Promise<ImportData> {
239+
if (this.fileRegistry[importData.fullPath]) {
240+
importData.found = true;
241+
return importData;
242+
}
243+
239244
try {
240245
await fs.access(importData.fullPath);
241246
importData.found = true;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Jest Snapshot v1, https://goo.gl/fbAQLP
2+
3+
exports[`file-registry 1`] = `
4+
".foo {
5+
color: red;
6+
}
7+
8+
"
9+
`;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import path from "path";
2+
import { Bundler } from "@src/bundler";
3+
4+
test("{{caseName}}", async done => {
5+
const projectDirectory = "{{projectDirectory}}";
6+
const testConfig = {{{json testConfig}}};
7+
const entryFile = path.join(projectDirectory, testConfig.entry);
8+
9+
const fileRegistry = Object.assign(
10+
{},
11+
...testConfig.registries.map((registry) => ({
12+
[path.join(projectDirectory, registry.path)]: registry.content
13+
}))
14+
);
15+
16+
try {
17+
const bundleResult = await new Bundler(fileRegistry, projectDirectory)
18+
.bundle(entryFile);
19+
20+
expect(bundleResult.bundledContent).toMatchSnapshot();
21+
done();
22+
} catch (error) {
23+
done.fail(error);
24+
}
25+
});

tests/cases/file-registry/foo.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.foo {
2+
color: red;
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
@import "not-exists-in-disk.scss";
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"entry": "main.scss",
3+
"registries": [
4+
{
5+
"path": "not-exists-in-disk.scss",
6+
"content": "@import \"foo\";"
7+
}
8+
]
9+
}

0 commit comments

Comments
 (0)