Skip to content

Commit f0d02dc

Browse files
MichaelDeBoeypieh
andauthored
chore(babel-preset-gatsby): Convert path-serializer to TS (#22035)
* Convert path-serializer to TS * Fix tests * Update packages/babel-preset-gatsby/src/utils/path-serializer.ts Co-Authored-By: Michal Piechowiak <misiek.piechowiak@gmail.com> * ignore built files * Revert "ignore built files" This reverts commit 51236aa. * adjust ignore in build scripts * no overwrites needed * unformat Co-authored-by: Michal Piechowiak <misiek.piechowiak@gmail.com>
1 parent f607506 commit f0d02dc

File tree

5 files changed

+27
-21
lines changed

5 files changed

+27
-21
lines changed

packages/babel-preset-gatsby/package.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
"license": "MIT",
3030
"main": "index.js",
3131
"scripts": {
32-
"build": "babel src --out-dir . --ignore **/__tests__ --ignore **/utils/path-serializer.js",
32+
"build": "babel src --out-dir . --ignore **/__tests__ --ignore **/utils/path-serializer.ts --extensions \".ts,.js\"",
3333
"prepare": "cross-env NODE_ENV=production npm run build",
34-
"watch": "babel -w src --out-dir . --ignore **/__tests__ --ignore **/utils/path-serializer.js"
34+
"watch": "babel -w src --out-dir . --ignore **/__tests__ --ignore **/utils/path-serializer.ts --extensions \".ts,.js\""
3535
},
3636
"devDependencies": {
3737
"@babel/cli": "^7.7.5",

packages/babel-preset-gatsby/src/__tests__/dependencies.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const preset = require(`../dependencies`)
2+
import * as pathSerializer from "../utils/path-serializer"
23

3-
expect.addSnapshotSerializer(require(`../utils/path-serializer`))
4+
expect.addSnapshotSerializer(pathSerializer)
45

56
describe(`dependencies`, () => {
67
it(`should specify proper presets and plugins`, () => {

packages/babel-preset-gatsby/src/__tests__/index.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
const preset = require(`../`)
21
const path = require(`path`)
32

4-
expect.addSnapshotSerializer(require(`../utils/path-serializer`))
3+
const preset = require(`../`)
4+
import * as pathSerializer from "../utils/path-serializer"
5+
6+
expect.addSnapshotSerializer(pathSerializer)
57

68
describe(`babel-preset-gatsby`, () => {
79
it.each([`build-stage`, `develop`, `build-javascript`, `build-html`])(

packages/babel-preset-gatsby/src/utils/path-serializer.js

-16
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { slash } from "gatsby-core-utils"
2+
3+
const cleanNodeModules = (dir: string): string => {
4+
const x = dir.split(`node_modules/`)
5+
6+
if (x.length <= 1) {
7+
return dir
8+
}
9+
10+
return slash(`<PROJECT_ROOT>/node_modules/${x[1]}`)
11+
}
12+
13+
export const test = (val: unknown): boolean =>
14+
typeof val === `string` && val !== cleanNodeModules(val)
15+
16+
export const print = (
17+
val: string,
18+
serialize: (val: string) => string
19+
): string => serialize(cleanNodeModules(val))

0 commit comments

Comments
 (0)