Skip to content

Commit

Permalink
chore(gatsby-parcel-config): stabilize ts compilation parcel output (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pieh committed Mar 1, 2022
1 parent 2cf474b commit f2bce35
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/gatsby-parcel-config/lib/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"*.{xml,rss,atom}": ["@parcel/transformer-xml"],
"url:*": ["...", "@parcel/transformer-raw"]
},
"namers": ["@parcel/namer-default"],
"namers": ["@gatsbyjs/parcel-namer-relative-to-cwd", "@parcel/namer-default"],
"runtimes": [
"@parcel/runtime-js",
"@parcel/runtime-browser-hmr",
Expand Down
2 changes: 2 additions & 0 deletions packages/gatsby-parcel-config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"parcel": "2.x"
},
"dependencies": {
"@gatsbyjs/parcel-namer-relative-to-cwd": "0.0.2",
"@parcel/bundler-default": "^2.3.1",
"@parcel/compressor-raw": "^2.3.1",
"@parcel/namer-default": "^2.3.1",
Expand All @@ -31,6 +32,7 @@
"@parcel/transformer-react-refresh-wrap": "^2.3.1"
},
"parcelDependencies": {
"@gatsbyjs/parcel-namer-relative-to-cwd": "0.0.2",
"@parcel/optimizer-data-url": "^2.3.1",
"@parcel/packager-raw-url": "^2.3.1",
"@parcel/packager-ts": "^2.3.1",
Expand Down
38 changes: 38 additions & 0 deletions packages/gatsby/src/utils/parcel/__tests__/compile-gatsby-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { readFile, remove, pathExists } from "fs-extra"
const dir = {
js: `${__dirname}/fixtures/js`,
ts: `${__dirname}/fixtures/ts`,
tsOnlyInLocal: `${__dirname}/fixtures/ts-only-in-local-plugin`,
}

jest.mock(`@parcel/core`, () => {
Expand All @@ -37,6 +38,15 @@ interface IMockedParcel extends Parcel {
options: unknown
}

let cwdToRestore
beforeAll(() => {
cwdToRestore = process.cwd()
})

afterAll(() => {
process.chdir(cwdToRestore)
})

describe(`gatsby file compilation`, () => {
describe(`constructBundler`, () => {
it(`should construct Parcel relative to passed directory`, () => {
Expand All @@ -60,6 +70,7 @@ describe(`gatsby file compilation`, () => {
describe(`compileGatsbyFiles`, () => {
describe(`js files are not touched`, () => {
beforeAll(async () => {
process.chdir(dir.js)
await remove(`${dir.js}/.cache`)
await compileGatsbyFiles(dir.js)
})
Expand All @@ -81,6 +92,7 @@ describe(`gatsby file compilation`, () => {

describe(`ts files are compiled`, () => {
beforeAll(async () => {
process.chdir(dir.ts)
await remove(`${dir.ts}/.cache`)
await compileGatsbyFiles(dir.ts)
})
Expand All @@ -105,5 +117,31 @@ describe(`gatsby file compilation`, () => {
expect(compiledGatsbyNode).toContain(`I am working!`)
})
})

describe(`ts only in local plugin files are compiled and outputted where expected`, () => {
beforeAll(async () => {
process.chdir(dir.tsOnlyInLocal)
await remove(`${dir.tsOnlyInLocal}/.cache`)
await compileGatsbyFiles(dir.tsOnlyInLocal)
})

it(`should compile gatsby-config.ts`, async () => {
const compiledGatsbyConfig = await readFile(
`${dir.tsOnlyInLocal}/.cache/compiled/plugins/gatsby-plugin-local/gatsby-config.js`,
`utf-8`
)

expect(compiledGatsbyConfig).toContain(`gatsby-config is working`)
})

it(`should compile gatsby-node.ts`, async () => {
const compiledGatsbyNode = await readFile(
`${dir.tsOnlyInLocal}/.cache/compiled/plugins/gatsby-plugin-local/gatsby-node.js`,
`utf-8`
)

expect(compiledGatsbyNode).toContain(`gatsby-node is working`)
})
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
console.log(`gatsby-config is working`)

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
console.log(`gatsby-node is working`)
30 changes: 30 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1671,6 +1671,15 @@
unique-filename "^1.1.1"
which "^1.3.1"

"@gatsbyjs/parcel-namer-relative-to-cwd@0.0.2":
version "0.0.2"
resolved "https://registry.yarnpkg.com/@gatsbyjs/parcel-namer-relative-to-cwd/-/parcel-namer-relative-to-cwd-0.0.2.tgz#e1586f1796aa773e53e0909025ea16e423c14391"
integrity sha512-ZeGxCbx13+zjpE/0HuJ/tjox9zfiYq9fGoAAi+RHP5vHSJCmJVO5hZbexQ/umlUyAkkkzC4p1WIpw1cYQTA8SA==
dependencies:
"@babel/runtime" "^7.15.4"
"@parcel/plugin" "2.3.1"
gatsby-core-utils "^3.8.2"

"@gatsbyjs/reach-router@^1.3.6":
version "1.3.6"
resolved "https://registry.yarnpkg.com/@gatsbyjs/reach-router/-/reach-router-1.3.6.tgz#4e8225836959be247890b66f21a3198a0589e34d"
Expand Down Expand Up @@ -11228,6 +11237,27 @@ gather-stream@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/gather-stream/-/gather-stream-1.0.0.tgz#b33994af457a8115700d410f317733cbe7a0904b"

gatsby-core-utils@^3.8.2:
version "3.8.2"
resolved "https://registry.yarnpkg.com/gatsby-core-utils/-/gatsby-core-utils-3.8.2.tgz#9c2869f93a740d20536b1e92c8020efd85d43e5f"
integrity sha512-UwANr9yd8ayLinPDoRbU/rRgoOBOS715qe2LYCxq6hAtRabHWTEM8Vj0wh7LmyVGexx8MFgvp2NKikG2TZ5pzQ==
dependencies:
"@babel/runtime" "^7.15.4"
ci-info "2.0.0"
configstore "^5.0.1"
fastq "^1.13.0"
file-type "^16.5.3"
fs-extra "^10.0.0"
got "^11.8.3"
import-from "^4.0.0"
lmdb "^2.1.7"
lock "^1.1.0"
node-object-hash "^2.3.10"
proper-lockfile "^4.1.2"
resolve-from "^5.0.0"
tmp "^0.2.1"
xdg-basedir "^4.0.0"

gauge@~2.7.3:
version "2.7.4"
resolved "https://registry.yarnpkg.com/gauge/-/gauge-2.7.4.tgz#2c03405c7538c39d7eb37b317022e325fb018bf7"
Expand Down

0 comments on commit f2bce35

Please sign in to comment.