Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #3142: undecorate: allow white spaces in cwd #3145

Merged
merged 2 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/seven-eggs-flash.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"mobx-undecorate": patch
---

fix #3142 allow white spaces in cwd
17 changes: 8 additions & 9 deletions packages/mobx-undecorate/__tests__/cli.spec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,18 @@ import { join, dirname } from "path"
import { readFileSync, writeFileSync, mkdirSync } from "fs"
const dedent = require("dedent-js")

test("run cli #2506", () => {
const testFile = join(__dirname, "fixtures", "some path", "some file.tsx")
test("run cli #2506 #3142", () => {
// #3142 - the white space must be in cwd
const cwd = join(__dirname, "fixtures", "some path");
const testFile = join(cwd, "some file.tsx")
const baseContent = dedent(`import { observable } from "mobx";
class Test {
@observable x = 1;
}
`)

mkdirSync(dirname(testFile))
`)
mkdirSync(dirname(testFile), { recursive: true })
writeFileSync(testFile, baseContent)
execSync("node ../../cli.js", {
cwd: join(__dirname, "fixtures")
})
execSync("node ../../../cli.js", { cwd })
expect(readFileSync(testFile, "utf8")).toMatchInlineSnapshot(`
"import { observable, makeObservable } from \\"mobx\\";
class Test {
Expand Down Expand Up @@ -58,7 +57,7 @@ test("run cli with --parseTsAsNonJsx #2754", () => {
}
`)

mkdirSync(dirname(testNonJsxFile))
mkdirSync(dirname(testNonJsxFile), { recursive: true })
Copy link
Collaborator Author

@urugator urugator Oct 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recursive: true just to silent the EEXIST error, which prevents re-running test without manually deleting the directory first

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that has become the default on Node a while back IIRC, so you might be on an older version? Anyway, no harm in there.

writeFileSync(testNonJsxFile, nonJsxContent)
writeFileSync(testJsxFile, jsxContent)
execSync("node ../../cli.js --parseTsAsNonJsx", {
Expand Down
6 changes: 3 additions & 3 deletions packages/mobx-undecorate/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,11 @@ function interpret_cli_args() {
spawnBin("jscodeshift", [
"--extensions=js,jsx,ts,tsx",
...process.argv.filter(arg => arg.startsWith("--")),
"-t", path.join(__dirname, "src", "undecorate.ts"),
"-t", `"${path.join(__dirname, "src", "undecorate.ts")}"`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Argh, I was hoping this was the exact problem that passing an argument array would fix. Anyway, thanks for finding this!


//this is arg to tell jscodeshift the dir to transform or fallback to process.cwd()
//originally just hard coded to process.cwd()
path.join(process.cwd(), interpret_cli_args())
`"${path.join(process.cwd(), interpret_cli_args())}"`

]);

Expand Down