Skip to content

Commit

Permalink
fix(build): allow filenames with multiple dots
Browse files Browse the repository at this point in the history
Fixes #4
  • Loading branch information
rexxars committed Apr 2, 2021
1 parent 51339b1 commit e577652
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 9 deletions.
9 changes: 0 additions & 9 deletions src/util/files.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,6 @@ function hasSourceFile(filePath, paths) {

// filePath: components/SomeInput
// paths: {source: '/plugin/src'}

// components/SomeInput.tsx => .tsx
const ext = path.extname(filePath)
if (ext) {
// If we already have an extension, we don't need to mess around with trying alternatives
const absPath = path.isAbsolute(filePath) ? filePath : path.resolve(paths.source, filePath)
return fileExists(absPath)
}

// MyComponent => /plugin/src/MyComponent
const pathStub = path.isAbsolute(filePath) ? filePath : path.resolve(paths.source, filePath)

Expand Down
7 changes: 7 additions & 0 deletions test/build-sanity.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,3 +137,10 @@ tap.test('throws on sanity.json being invalid (unprefixed implementation)', opti
t.equal(exitCode, 1, 'should have exit code 1')
t.includes(stderr, '"implements" must be prefixed with "part:" - got "some-part-name" (parts[0])')
})

tap.test('handles filenames with multiple dots', options, async (t) => {
const fixtureDir = path.join(baseFixturesDir, 'dotted-filename-part-sanity-json')
const {stdout, exitCode} = await execa(sanipack, ['build', fixtureDir], {reject: false})
t.equal(exitCode, 0, 'should have exit code 1')
t.includes(stdout, 'Successfully compiled 1 file with Babel')
})

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "sanity-plugin-unprefixed-part-sanity-json",
"version": "1.0.0",
"private": true,
"main": "./lib/my.schema.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [
"sanity",
"sanity-plugin"
],
"author": "Some person",
"license": "MIT"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"paths": {
"source": "./src",
"compiled": "./lib"
},

"parts": [
{
"implements": "part:@sanity/base/schema-type",
"path": "my.schema"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default {
name: 'myThing',
type: 'document',
field: [{name: 'title', type: 'string'}],
}

0 comments on commit e577652

Please sign in to comment.