Skip to content

Commit 0b1c38e

Browse files
committed
removed getJSON in favour of the css :export syntax
1 parent 2e8ce1c commit 0b1c38e

13 files changed

+119
-239
lines changed

CHANGELOG.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
1616
### Removed
1717

1818
- "test" script is now only in the root, instead of in every package.
19-
- No longer testing for Node 7
19+
- [BREAKING] No longer testing for Node 7
2020

2121
### Changed
2222

@@ -26,7 +26,12 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2626
- [BREAKING] Removed the UMD build
2727

2828
- `postcss-container-query`
29-
- Minimum Node version lifted to v8
29+
- [BREAKING] Minimum Node version lifted to v8
30+
- [BREAKING] Dropped the `getJSON` option, and no json is saved by default.
31+
The new behaviour is to use the ICSS `:export` syntax, which then can be
32+
imported through css-loader. (The meta object is still passed down in the
33+
postcss plugin messages in case it's needed.)
34+
- [BREAKING] `saveMeta` is removed
3035

3136
## [2.7.4]
3237

packages/postcss-container-query/rollup.config.js

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,14 @@ const generate = ({ input, output }) => ({
66
input,
77
output: [{ file: output, format: "cjs" }],
88
plugins: [flow(), babel(), terser()],
9-
external: [
10-
"postcss",
11-
"lodash/trim",
12-
"fs",
13-
"@zeecoder/container-query-meta-builder"
14-
]
9+
external: ["postcss", "lodash/trim", "@zeecoder/container-query-meta-builder"]
1510
});
1611

1712
export default [
1813
generate({
1914
input: "src/containerQuery.js",
2015
output: "dist/index.js"
2116
}),
22-
generate({
23-
input: "src/saveMeta.js",
24-
output: "./saveMeta.js"
25-
}),
2617
generate({
2718
input: "src/getMetadataFromMessages.js",
2819
output: "./getMetadataFromMessages.js"

packages/postcss-container-query/src/containerQuery.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import postcss from "postcss";
22
import hasContainerDefinition from "./hasContainerDefinition";
33
import extractPropsFromNode from "./extractPropsFromNode";
4-
import saveMeta from "./saveMeta";
54
import MetaBuilder from "@zeecoder/container-query-meta-builder";
65

76
const plugin = "postcss-container-query";
@@ -58,13 +57,11 @@ const walkRules = (root, opts, ruleHandler) => {
5857

5958
/**
6059
* @param {{
61-
* [getJSON]: function,
6260
* [singleContainer]: boolean,
6361
* [exportMetaInCss]: boolean|string,
6462
* }} options
6563
*/
6664
function containerQuery(options = {}) {
67-
const getJSON = options.getJSON || saveMeta;
6865
const singleContainer = options.singleContainer !== false;
6966
const exportMetaInCss =
7067
typeof options.exportMetaInCss !== "undefined"
@@ -163,10 +160,6 @@ function containerQuery(options = {}) {
163160
filepath
164161
});
165162

166-
if (typeof getJSON === "function") {
167-
getJSON(filepath, meta);
168-
}
169-
170163
// The following is picked up by css-loader, therefore making importing json
171164
// files obsolete
172165
if (exportMetaInCss) {

packages/postcss-container-query/src/containerQuery.spec.js

Lines changed: 9 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import postcss from "postcss";
2-
import Root from "../__mocks__/Root";
32
import * as regularTest from "./test/regular";
43
import * as customPropertiesTest from "./test/custom-properties";
54
import * as exessContainerDeclarationTest from "./test/exess-container-declaration";
@@ -9,12 +8,11 @@ import * as missingContainerDelcarationTest from "./test/missing-container-decla
98
import * as missingDeclarationWithRUnitsTest from "./test/missing-declaration-with-r-units";
109
import * as selfTest from "./test/self";
1110
import * as simpleTest from "./test/simple";
12-
import * as metaExportTest from "./test/meta-export";
1311
import * as metaNamedExportTest from "./test/meta-named-export";
12+
import * as disabledMetaExportTest from "./test/disabled-meta-export";
1413
import fs from "fs";
1514
import containerQuery from "./containerQuery";
1615
import getMetadataFromMessages from "../getMetadataFromMessages";
17-
import saveMeta from "../saveMeta";
1816

1917
jest.mock("fs");
2018

@@ -27,19 +25,13 @@ jest.mock("fs");
2725
* }>}
2826
*/
2927
const processCss = async (rawCSS, options = {}) => {
30-
let getJsonMeta = null;
31-
options.getJSON = (path, meta) => (getJsonMeta = meta);
32-
3328
const { css, messages } = await postcss([containerQuery(options)]).process(
3429
rawCSS,
3530
{ from: "from.css", to: "to.css" }
3631
);
3732

3833
const meta = getMetadataFromMessages(messages);
3934

40-
// As long as the `getJSON` option is supported, this is important
41-
expect(getJsonMeta).toEqual(meta);
42-
4335
return { css, meta };
4436
};
4537

@@ -52,32 +44,19 @@ const processCss = async (rawCSS, options = {}) => {
5244
* @param {{}} [options] plugin options
5345
*/
5446
const assertProcessingResult = async (testObj, options = {}) => {
55-
const { css, meta } = await processCss(testObj.cssInput, {
56-
exportMetaInCss: false,
57-
...options
58-
});
47+
const { css, meta } = await processCss(testObj.cssInput, options);
5948

6049
expect(css).toBe(testObj.cssOutput);
6150
expect(meta).toEqual(testObj.meta);
6251
};
6352

6453
test('should avoid accidentally creating ".default" exports', () => {
65-
expect(typeof saveMeta).toBe("function");
6654
expect(typeof getMetadataFromMessages).toBe("function");
6755
expect(typeof containerQuery).toBe("function");
68-
expect(typeof saveMeta.default).toBe("undefined");
6956
expect(typeof getMetadataFromMessages.default).toBe("undefined");
7057
expect(typeof containerQuery.default).toBe("undefined");
7158
});
7259

73-
test("should use the default json saving function if none was supplied", () => {
74-
const pluginInstance = containerQuery({ exportMetaInCss: false });
75-
76-
pluginInstance(new Root(), { messages: [] });
77-
78-
expect(fs.readFile).toHaveBeenCalledTimes(1);
79-
});
80-
8160
test("should throw on missing container declaration", () => {
8261
expect.assertions(1);
8362

@@ -103,16 +82,10 @@ test("should throw on missing container declaration when the container has r-uni
10382
});
10483

10584
test("should ignore unrecognised at-rules, like @keyframes", () =>
106-
assertProcessingResult(unrecognisedAtRulesTest, {
107-
singleContainer: false,
108-
exportMetaInCss: false
109-
}));
85+
assertProcessingResult(unrecognisedAtRulesTest, { singleContainer: false }));
11086

11187
test("should properly process CSS", () =>
112-
assertProcessingResult(regularTest, {
113-
singleContainer: false,
114-
exportMetaInCss: false
115-
}));
88+
assertProcessingResult(regularTest, { singleContainer: false }));
11689

11790
// This also tests that containers are processed even without queries
11891
test("should detect the first class as the container by default", () =>
@@ -137,10 +110,12 @@ test("should handle :self", () => assertProcessingResult(selfTest));
137110
test("should be able to run this simple test", () =>
138111
assertProcessingResult(simpleTest));
139112

140-
test("should export the meta in the css by default", () =>
141-
assertProcessingResult(metaExportTest, { exportMetaInCss: undefined }));
142-
143113
test("should be able to export the meta under a custom export", () =>
144114
assertProcessingResult(metaNamedExportTest, {
145115
exportMetaInCss: "custom-meta"
146116
}));
117+
118+
test("should be able to disable the css meta export", () =>
119+
assertProcessingResult(disabledMetaExportTest, {
120+
exportMetaInCss: false
121+
}));

packages/postcss-container-query/src/saveMeta.js

Lines changed: 0 additions & 26 deletions
This file was deleted.

packages/postcss-container-query/src/saveMeta.spec.js

Lines changed: 0 additions & 64 deletions
This file was deleted.

packages/postcss-container-query/src/test/container-auto-detection.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,7 @@ export const cssInput = `
1515
.Container {
1616
@define-container;
1717
font-size: 2rh;
18-
}
19-
`;
20-
21-
export const cssOutput = `
22-
.Container {
23-
border: none;
24-
}
25-
26-
.Container {
27-
}
28-
`;
18+
}`;
2919

3020
export const meta = {
3121
[SELECTOR]: ".Container",
@@ -42,3 +32,13 @@ export const meta = {
4232
}
4333
]
4434
};
35+
36+
export const cssOutput = `
37+
.Container {
38+
border: none;
39+
}
40+
41+
.Container {
42+
}
43+
44+
:export { meta: '${JSON.stringify(meta)}' }`;

packages/postcss-container-query/src/test/custom-properties.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ export const cssInput = `
1515
}
1616
`;
1717

18-
export const cssOutput = `
19-
.Container {
20-
}
21-
`;
22-
2318
export const meta = {
2419
[SELECTOR]: ".Container",
2520
[QUERIES]: [
@@ -37,3 +32,9 @@ export const meta = {
3732
}
3833
]
3934
};
35+
36+
export const cssOutput = `
37+
.Container {
38+
}
39+
:export { meta: '${JSON.stringify(meta)}' }
40+
`;

packages/postcss-container-query/src/test/meta-export.js renamed to packages/postcss-container-query/src/test/disabled-meta-export.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,4 @@ export const meta = {
4646
export const cssOutput = `
4747
.Container {
4848
}
49-
:export { meta: '${JSON.stringify(meta)}' }
5049
`;

0 commit comments

Comments
 (0)