Skip to content

Commit

Permalink
chore(babel-preset-gatsby): Convert path-serializer to TS (#22035)
Browse files Browse the repository at this point in the history
* Convert path-serializer to TS

* Fix tests

* Update packages/babel-preset-gatsby/src/utils/path-serializer.ts

Co-Authored-By: Michal Piechowiak <[email protected]>

* 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 <[email protected]>
  • Loading branch information
MichaelDeBoey and pieh authored Mar 9, 2020
1 parent f607506 commit f0d02dc
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 21 deletions.
4 changes: 2 additions & 2 deletions packages/babel-preset-gatsby/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
"license": "MIT",
"main": "index.js",
"scripts": {
"build": "babel src --out-dir . --ignore **/__tests__ --ignore **/utils/path-serializer.js",
"build": "babel src --out-dir . --ignore **/__tests__ --ignore **/utils/path-serializer.ts --extensions \".ts,.js\"",
"prepare": "cross-env NODE_ENV=production npm run build",
"watch": "babel -w src --out-dir . --ignore **/__tests__ --ignore **/utils/path-serializer.js"
"watch": "babel -w src --out-dir . --ignore **/__tests__ --ignore **/utils/path-serializer.ts --extensions \".ts,.js\""
},
"devDependencies": {
"@babel/cli": "^7.7.5",
Expand Down
3 changes: 2 additions & 1 deletion packages/babel-preset-gatsby/src/__tests__/dependencies.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const preset = require(`../dependencies`)
import * as pathSerializer from "../utils/path-serializer"

expect.addSnapshotSerializer(require(`../utils/path-serializer`))
expect.addSnapshotSerializer(pathSerializer)

describe(`dependencies`, () => {
it(`should specify proper presets and plugins`, () => {
Expand Down
6 changes: 4 additions & 2 deletions packages/babel-preset-gatsby/src/__tests__/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
const preset = require(`../`)
const path = require(`path`)

expect.addSnapshotSerializer(require(`../utils/path-serializer`))
const preset = require(`../`)
import * as pathSerializer from "../utils/path-serializer"

expect.addSnapshotSerializer(pathSerializer)

describe(`babel-preset-gatsby`, () => {
it.each([`build-stage`, `develop`, `build-javascript`, `build-html`])(
Expand Down
16 changes: 0 additions & 16 deletions packages/babel-preset-gatsby/src/utils/path-serializer.js

This file was deleted.

19 changes: 19 additions & 0 deletions packages/babel-preset-gatsby/src/utils/path-serializer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { slash } from "gatsby-core-utils"

const cleanNodeModules = (dir: string): string => {
const x = dir.split(`node_modules/`)

if (x.length <= 1) {
return dir
}

return slash(`<PROJECT_ROOT>/node_modules/${x[1]}`)
}

export const test = (val: unknown): boolean =>
typeof val === `string` && val !== cleanNodeModules(val)

export const print = (
val: string,
serialize: (val: string) => string
): string => serialize(cleanNodeModules(val))

0 comments on commit f0d02dc

Please sign in to comment.