Skip to content

Commit 6d34a3d

Browse files
authored
fix: explicitly provide path to babel plugins (#3482)
* fix: explicitly provide path to babel plugins * docs: add a comment explaining the path stuff
1 parent 09305e0 commit 6d34a3d

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

packages/typeless-sample-bot/src/app.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ import {
2626
waitForAllSamples,
2727
fromArray,
2828
} from './samples.js';
29-
import url from 'node:url';
3029

3130
let returnValue = 0;
3231

packages/typeless-sample-bot/src/import-to-require.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
// Reference notes:
1516
// https://lihautan.com/step-by-step-guide-for-writing-a-babel-transformation/
1617
// https://lihautan.com/babel-ast-explorer/
1718
// https://github.com/esamattis/babel-plugin-ts-optchain/blob/master/packages/babel-plugin-ts-optchain/src/plugin.ts

packages/typeless-sample-bot/src/samples.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,24 @@ export async function* filterByContents(
8080

8181
// Instead of a babelrc, this is used so that we can get more control over
8282
// the transform process.
83+
//
84+
// The heavy path manipulation is required here to work around a problem
85+
// with finding Babel plugins on the path when running the bot from
86+
// outside its own tree. Babel will attempt to resolve plugins to
87+
// the most proximate node_modules, which will be the package being
88+
// operated upon, not us.
8389
const __dirname = path.dirname(fileURLToPath(import.meta.url));
90+
const ptPath = path.join(
91+
__dirname,
92+
'..',
93+
'..',
94+
'node_modules',
95+
'@babel',
96+
'preset-typescript'
97+
);
8498
const itrPath = path.join(__dirname, 'import-to-require');
8599
const babelConfig = {
86-
presets: [['@babel/preset-typescript', {}]],
100+
presets: [[ptPath, {}]],
87101
plugins: [[itrPath]],
88102
parserOpts: {} as babel.ParserOptions,
89103
generatorOpts: {

0 commit comments

Comments
 (0)