Skip to content

Commit e58cf90

Browse files
authored
css, integration: Replace outdent dependency with dedent (#1386)
1 parent 6066606 commit e58cf90

File tree

11 files changed

+59
-44
lines changed

11 files changed

+59
-44
lines changed

.changeset/cuddly-bottles-grow.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
'@vanilla-extract/integration': patch
3+
'@vanilla-extract/css': patch
4+
---
5+
6+
Replace `outdent` dependency with `dedent`

packages/css/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,11 @@
113113
"css-what": "^6.1.0",
114114
"cssesc": "^3.0.0",
115115
"csstype": "^3.0.7",
116+
"dedent": "^1.5.1",
116117
"deep-object-diff": "^1.1.9",
117118
"deepmerge": "^4.2.2",
118119
"media-query-parser": "^2.0.2",
119-
"modern-ahocorasick": "^1.0.0",
120-
"outdent": "^0.8.0"
120+
"modern-ahocorasick": "^1.0.0"
121121
},
122122
"devDependencies": {
123123
"@types/cssesc": "^3.0.0"

packages/css/src/fileScope.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import outdent from 'outdent';
1+
import dedent from 'dedent';
22
import { onBeginFileScope, onEndFileScope } from './adapter';
33
import type { FileScope } from './types';
44

@@ -29,7 +29,7 @@ export function hasFileScope() {
2929
export function getFileScope(): FileScope {
3030
if (fileScopes.length === 0) {
3131
throw new Error(
32-
outdent`
32+
dedent`
3333
Styles were unable to be assigned to a file. This is generally caused by one of the following:
3434
3535
- You may have created styles outside of a '.css.ts' context

packages/css/src/style.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import cssesc from 'cssesc';
2-
import outdent from 'outdent';
2+
import dedent from 'dedent';
33
import deepmerge from 'deepmerge';
44

55
import type {
@@ -105,7 +105,7 @@ export function fontFace(
105105

106106
for (const singleRule of rules) {
107107
if ('fontFamily' in singleRule) {
108-
throw new Error(outdent`
108+
throw new Error(dedent`
109109
This function creates and returns a hashed font-family name, so the "fontFamily" property should not be provided.
110110
111111
If you'd like to define a globally scoped custom font, you can use the "globalFontFace" function instead.

packages/css/src/validateMediaQuery.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import outdent from 'outdent';
1+
import dedent from 'dedent';
22
import { toAST } from 'media-query-parser';
33

44
const createMediaQueryError = (mediaQuery: string, msg: string) =>
55
new Error(
6-
outdent`
6+
dedent`
77
Invalid media query: "${mediaQuery}"
88
99
${msg}

packages/css/src/validateSelector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { parse } from 'css-what';
22
import cssesc from 'cssesc';
3-
import outdent from 'outdent';
3+
import dedent from 'dedent';
44

55
// https://stackoverflow.com/questions/3561493/is-there-a-regexp-escape-function-in-javascript
66
function escapeRegex(string: string) {
@@ -53,7 +53,7 @@ export const validateSelector = (selector: string, targetClassName: string) => {
5353
}
5454
} catch (err) {
5555
throw new Error(
56-
outdent`
56+
dedent`
5757
Invalid selector: ${replaceTarget()}
5858
5959
Style selectors must target the '&' character (along with any modifiers), e.g. ${'`${parent} &`'} or ${'`${parent} &:hover`'}.

packages/integration/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@
1818
"@babel/plugin-syntax-typescript": "^7.23.3",
1919
"@vanilla-extract/babel-plugin-debug-ids": "^1.0.5",
2020
"@vanilla-extract/css": "^1.14.2",
21+
"dedent": "^1.5.1",
2122
"esbuild": "npm:esbuild@~0.17.6 || ~0.18.0 || ~0.19.0",
2223
"eval": "0.1.8",
2324
"find-up": "^5.0.0",
2425
"javascript-stringify": "^2.0.1",
2526
"mlly": "^1.4.2",
26-
"outdent": "^0.8.0",
2727
"vite": "^5.0.11",
2828
"vite-node": "^1.2.0"
2929
},

packages/integration/src/addFileScope.test.ts

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { outdent } from 'outdent';
1+
import dedent from 'dedent';
22
import { sep, posix, win32 } from 'path';
33

44
import { addFileScope, normalizePath } from './addFileScope';
@@ -13,7 +13,7 @@ expect.addSnapshotSerializer({
1313

1414
describe('ESM', () => {
1515
test('should add missing fileScope', () => {
16-
const source = outdent`
16+
const source = dedent`
1717
import {style} from '@vanilla-extract/css';
1818
1919
export const myStyle = style({});
@@ -37,7 +37,7 @@ describe('ESM', () => {
3737
});
3838

3939
test('should add global adapter setup when "globalAdapterIdentifier" is provided', () => {
40-
const source = outdent`
40+
const source = dedent`
4141
import {style} from '@vanilla-extract/css';
4242
4343
export const myStyle = style({});
@@ -65,7 +65,7 @@ describe('ESM', () => {
6565
});
6666

6767
test('should update existing fileScope', () => {
68-
const source = outdent`
68+
const source = dedent`
6969
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
7070
setFileScope("some-weird-file", "some-weird-package");
7171
import {style} from '@vanilla-extract/css';
@@ -92,7 +92,7 @@ describe('ESM', () => {
9292
});
9393

9494
test('should update existing fileScope with newlines', () => {
95-
const source = outdent`
95+
const source = dedent`
9696
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
9797
setFileScope(
9898
"some-weird-file",
@@ -122,7 +122,7 @@ describe('ESM', () => {
122122
});
123123

124124
test('should handle namespaced filescope calls', () => {
125-
const source = outdent`
125+
const source = dedent`
126126
import * as vanillaFileScope from "@vanilla-extract/css/fileScope";
127127
vanillaFileScope.setFileScope("some-weird-file");
128128
import {style} from '@vanilla-extract/css';
@@ -151,7 +151,7 @@ describe('ESM', () => {
151151

152152
describe('CJS', () => {
153153
test('should add missing fileScope', () => {
154-
const source = outdent`
154+
const source = dedent`
155155
const _css = require('@vanilla-extract/css');
156156
157157
var myStyle = _css.style({});
@@ -177,7 +177,7 @@ describe('CJS', () => {
177177
});
178178

179179
test('should add global adapter setup when "globalAdapterIdentifier" is provided', () => {
180-
const source = outdent`
180+
const source = dedent`
181181
const _css = require('@vanilla-extract/css');
182182
183183
var myStyle = _css.style({});
@@ -207,7 +207,7 @@ describe('CJS', () => {
207207
});
208208

209209
test('should update existing fileScope', () => {
210-
const source = outdent`
210+
const source = dedent`
211211
const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
212212
__vanilla_filescope__.setFileScope("some-weird-file", "some-weird-package");
213213
const _css = require('@vanilla-extract/css');
@@ -236,7 +236,7 @@ describe('CJS', () => {
236236
});
237237

238238
test('should update existing fileScope with newlines', () => {
239-
const source = outdent`
239+
const source = dedent`
240240
const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
241241
__vanilla_filescope__.setFileScope(
242242
"some-weird-file",
@@ -280,7 +280,7 @@ test('platform-specific relative path', () => {
280280
},
281281
}[sep];
282282

283-
const source = outdent`
283+
const source = dedent`
284284
import { style } from '@vanilla-extract/css';
285285
286286
export const myStyle = style({});

packages/integration/src/addFileScope.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { posix, relative, win32 } from 'path';
22
import { detectSyntax } from 'mlly';
3-
import outdent from 'outdent';
3+
import dedent from 'dedent';
44

55
// Inlined from @rollup/pluginutils
66
// https://github.com/rollup/plugins/blob/33174f956304ab4aad4bbaba656f627c31679dc5/packages/pluginutils/src/normalizePath.ts#L5-L7
@@ -33,14 +33,14 @@ export function addFileScope({
3333
);
3434
} else {
3535
if (hasESM && !isMixed) {
36-
source = outdent`
36+
source = dedent`
3737
import { setFileScope, endFileScope } from "@vanilla-extract/css/fileScope";
3838
setFileScope("${normalizedPath}", "${packageName}");
3939
${source}
4040
endFileScope();
4141
`;
4242
} else {
43-
source = outdent`
43+
source = dedent`
4444
const __vanilla_filescope__ = require("@vanilla-extract/css/fileScope");
4545
__vanilla_filescope__.setFileScope("${normalizedPath}", "${packageName}");
4646
${source}
@@ -55,7 +55,7 @@ export function addFileScope({
5555
? 'import * as __vanilla_css_adapter__ from "@vanilla-extract/css/adapter";'
5656
: 'const __vanilla_css_adapter__ = require("@vanilla-extract/css/adapter");';
5757

58-
source = outdent`
58+
source = dedent`
5959
${adapterImport}
6060
__vanilla_css_adapter__.setAdapter(${globalAdapterIdentifier});
6161
${source}

packages/integration/src/processVanillaFile.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,29 +2,37 @@ import { FileScope, Adapter } from '@vanilla-extract/css';
22
import { transformCss } from '@vanilla-extract/css/transformCss';
33
import evalCode from 'eval';
44
import { stringify } from 'javascript-stringify';
5-
import outdent from 'outdent';
5+
import dedent from 'dedent';
66

77
import { hash } from './hash';
88
import { serializeCss } from './serialize';
99
import type { IdentifierOption } from './types';
1010

1111
const originalNodeEnv = process.env.NODE_ENV;
1212

13+
// Copied from https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore/blob/51f83bd3db728fd7ee177de1ffc253fdb99c537f/README.md#_isplainobject
1314
function isPlainObject(value: unknown) {
14-
if (typeof value !== 'object' || value === null) return false;
15+
if (typeof value !== 'object' || value === null) {
16+
return false;
17+
}
18+
19+
if (Object.prototype.toString.call(value) !== '[object Object]') {
20+
return false;
21+
}
1522

16-
if (Object.prototype.toString.call(value) !== '[object Object]') return false;
23+
const prototype = Object.getPrototypeOf(value);
24+
if (prototype === null) {
25+
return true;
26+
}
1727

18-
const proto = Object.getPrototypeOf(value);
19-
if (proto === null) return true;
28+
const constructor =
29+
Object.prototype.hasOwnProperty.call(prototype, 'constructor') &&
30+
prototype.constructor;
2031

21-
const Ctor =
22-
Object.prototype.hasOwnProperty.call(proto, 'constructor') &&
23-
proto.constructor;
2432
return (
25-
typeof Ctor === 'function' &&
26-
Ctor instanceof Ctor &&
27-
Function.prototype.call(Ctor) === Function.prototype.call(value)
33+
typeof constructor === 'function' &&
34+
constructor instanceof constructor &&
35+
Function.prototype.call(constructor) === Function.prototype.call(value)
2836
);
2937
}
3038

@@ -265,7 +273,7 @@ function stringifyExports(
265273
}
266274
}
267275

268-
throw new Error(outdent`
276+
throw new Error(dedent`
269277
Invalid exports.
270278
271279
You can only export plain objects, arrays, strings, numbers and null/undefined.

0 commit comments

Comments
 (0)