@compiled/parcel-optimizer 0.1.1

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/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # @compiled/parcel-optimizer
2
+
3
+ Parcel plugin for Compiled.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm i @compiled/parcel-optimizer
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ Detailed docs and example usage can be [found on the documentation website](https://compiledcssinjs.com/docs/pkg-parcel-optimizer).
@@ -0,0 +1,3 @@
1
+ import { Optimizer } from '@parcel/plugin';
2
+ declare const _default: Optimizer<unknown>;
3
+ export default _default;
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const css_1 = require("@compiled/css");
4
+ const plugin_1 = require("@parcel/plugin");
5
+ exports.default = new plugin_1.Optimizer({
6
+ async optimize({ contents, map }) {
7
+ return { contents: (0, css_1.sort)(contents.toString()), map };
8
+ },
9
+ });
10
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAAA,uCAAqC;AACrC,2CAA2C;AAE3C,kBAAe,IAAI,kBAAS,CAAC;IAC3B,KAAK,CAAC,QAAQ,CAAC,EAAE,QAAQ,EAAE,GAAG,EAAE;QAC9B,OAAO,EAAE,QAAQ,EAAE,IAAA,UAAI,EAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC;IACtD,CAAC;CACF,CAAC,CAAC"}
package/package.json ADDED
@@ -0,0 +1,35 @@
1
+ {
2
+ "name": "@compiled/parcel-optimizer",
3
+ "version": "0.1.1",
4
+ "description": "A familiar and performant compile time CSS-in-JS library for React.",
5
+ "bugs": "https://github.com/atlassian-labs/compiled/issues/new?assignees=&labels=bug&template=bug_report.md",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "https://github.com/atlassian-labs/compiled.git",
9
+ "directory": "packages/parcel-optimizer"
10
+ },
11
+ "license": "Apache-2.0",
12
+ "author": "Michael Dougall",
13
+ "sideEffects": false,
14
+ "main": "./dist/index.js",
15
+ "module": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "files": [
18
+ "dist",
19
+ "src"
20
+ ],
21
+ "dependencies": {
22
+ "@compiled/css": "^0.8.1",
23
+ "@parcel/plugin": "^2.3.1"
24
+ },
25
+ "devDependencies": {
26
+ "@parcel/core": "^2.3.1",
27
+ "@parcel/fs": "^2.3.1",
28
+ "@parcel/types": "^2.3.1",
29
+ "ts-node": "^10.4.0",
30
+ "tsconfig-paths": "^3.12.0"
31
+ },
32
+ "engines": {
33
+ "parcel": "^2.0.0"
34
+ }
35
+ }
@@ -0,0 +1,75 @@
1
+ /**
2
+ * @jest-environment node
3
+ */
4
+
5
+ import { join } from 'path';
6
+
7
+ import Parcel, { createWorkerFarm } from '@parcel/core';
8
+ import { MemoryFS } from '@parcel/fs';
9
+
10
+ const rootPath = join(__dirname, '..', '..', '..', '..');
11
+ const fixtureRoot = join(rootPath, 'fixtures/parcel-optimizer-test-app');
12
+
13
+ const workerFarm = createWorkerFarm();
14
+ const outputFS = new MemoryFS(workerFarm);
15
+
16
+ const parcel = new Parcel({
17
+ config: join(fixtureRoot, '.parcelrc'),
18
+ entries: [join(fixtureRoot, 'src', 'index.html')],
19
+ outputFS,
20
+ targets: {
21
+ default: {
22
+ distDir: join(fixtureRoot, 'dist'),
23
+ },
24
+ },
25
+ workerFarm,
26
+ });
27
+
28
+ afterAll(() => {
29
+ workerFarm.end();
30
+ });
31
+
32
+ describe('optimizer', () => {
33
+ it('sorts css rules', async () => {
34
+ const { changedAssets, bundleGraph } = await parcel.run();
35
+ const asset = Array.from(changedAssets.values()).find(
36
+ (asset) => asset.filePath === join(fixtureRoot, '/src/styles.css')
37
+ );
38
+
39
+ const outputCss = await outputFS.readFile(
40
+ bundleGraph.getBundlesWithAsset(asset!)[0].filePath,
41
+ 'utf8'
42
+ );
43
+ expect(outputCss).toMatchInlineSnapshot(`
44
+ "
45
+
46
+ .color-blue {
47
+ color: blue;
48
+ }
49
+
50
+ .color-blue:focus {
51
+ color: orange;
52
+ }
53
+
54
+ .color-blue:hover {
55
+ color: green;
56
+ }
57
+
58
+ @media screen {
59
+ .media-screen-color-red {
60
+ color: red;
61
+ }
62
+ }
63
+
64
+ @media (min-width: 500px) {
65
+ .media-min-width-border {
66
+ border: 2px solid red;
67
+ }
68
+ .media-min-width-border:before {
69
+ content: 'large screen';
70
+ }
71
+ }
72
+ "
73
+ `);
74
+ }, 30000);
75
+ });
package/src/index.ts ADDED
@@ -0,0 +1,8 @@
1
+ import { sort } from '@compiled/css';
2
+ import { Optimizer } from '@parcel/plugin';
3
+
4
+ export default new Optimizer({
5
+ async optimize({ contents, map }) {
6
+ return { contents: sort(contents.toString()), map };
7
+ },
8
+ });