Skip to content

Commit

Permalink
add new reverse-exports package
Browse files Browse the repository at this point in the history
  • Loading branch information
mansona committed Oct 24, 2023
1 parent 3934dea commit a1343c1
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 0 deletions.
7 changes: 7 additions & 0 deletions packages/reverse-exports/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/node_modules
/src/**/*.js
/src/**/*.d.ts
/src/**/*.map
/tests/**/*.js
/tests/**/*.d.ts
/tests/**/*.map
4 changes: 4 additions & 0 deletions packages/reverse-exports/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
testEnvironment: 'node',
testMatch: ['<rootDir>/tests/**/*.test.js'],
};
14 changes: 14 additions & 0 deletions packages/reverse-exports/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "reverse-exports",
"version": "0.0.0",
"description": "",
"main": "src/index.js",
"scripts": {
"test": "jest"
},
"keywords": [],
"author": "",
"license": "ISC",
"devDependencies": {
}
}
9 changes: 9 additions & 0 deletions packages/reverse-exports/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { posix } from 'path';

export default function reversePackageExports(
packageJSON: { exports?: any; name: string },
relativePath: string
): string {
// TODO actually read from exports and don't be super naive
return posix.join(packageJSON.name, relativePath.replace(/^.\/dist\//, `./`).replace(/\.js$/, ''));
}
10 changes: 10 additions & 0 deletions packages/reverse-exports/tests/reverse-exports.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import reversePackageExports from '../src';

describe('reverse exports', function () {
it('correctly reversed exports', function () {
// TODO actually pass exports to this for it to read from
expect(reversePackageExports({ name: 'best-addon' }, './dist/_app_/components/face.js')).toBe(
'best-addon/_app_/components/face'
);
});
});

0 comments on commit a1343c1

Please sign in to comment.