forked from fabricjs/fabric.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci(e2e): support relative imports (fabricjs#9108)
- Loading branch information
Showing
13 changed files
with
342 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// https://github.com/viruscamp/babel-plugin-transform-imports#using-a-function-as-the-transformer | ||
|
||
const path = require('path'); | ||
const testsDir = path.resolve('./e2e/tests'); | ||
const testsBuiltDir = path.resolve('./e2e/dist'); | ||
|
||
function resolve(file) { | ||
const found = ['', '.ts', '/index.ts'] | ||
.map((resolution) => `${file}${resolution}`) | ||
.find((file) => { | ||
try { | ||
return require.resolve(file); | ||
} catch (error) { | ||
return false; | ||
} | ||
}); | ||
if (!found) { | ||
console.error(`Failed to resolve ${file}`); | ||
process.exit(1); | ||
} | ||
return require.resolve(found).replace(/\.ts$/, '.js'); | ||
} | ||
|
||
module.exports = { | ||
extends: '../.babelrcAlt', | ||
plugins: [ | ||
[ | ||
'transform-imports', | ||
{ | ||
'\\..*': { | ||
skipDefaultConversion: true, | ||
transform: function (importName, matches, filename) { | ||
const file = resolve( | ||
path.resolve(path.dirname(filename), `${matches[0]}`) | ||
); | ||
return `/${path | ||
.relative( | ||
process.cwd(), | ||
file.startsWith(testsDir) | ||
? path.resolve(testsBuiltDir, path.relative(testsDir, file)) | ||
: file | ||
) | ||
.replaceAll('\\', '/')}`; | ||
}, | ||
}, | ||
}, | ||
], | ||
], | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
import { readJSONSync } from 'fs-extra'; | ||
|
||
/** | ||
* The import map used by `./utils/setupApp` to inject into the page | ||
* so test scripts can use modules (relative imports don't seem to work out of the box) | ||
* The import map used by `./utils/setupApp` to inject into the page so test scripts can use modules. | ||
* | ||
* Relative imports are supported thanks to babel, see `./.babelrc.js`. | ||
* | ||
* **IMPORTANT**: be sure to update the paths field in `./tsconfig.json` to reflect imports correctly | ||
*/ | ||
export default { | ||
fabric: readJSONSync('./package.json').module.slice(1), | ||
test: '/e2e/dist/test.js', | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.