Skip to content
Draft
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
73 changes: 73 additions & 0 deletions dev/bin/lint.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import path from 'node:path';
import chalk from 'chalk';
import { packageJson, project } from 'ember-apply';
import { execa, execaCommand } from 'execa';
import { globbySync } from 'globby';

const [, , command] = process.argv;
// process.cwd() is whatever pnpm decides to do
Expand Down Expand Up @@ -36,6 +37,8 @@ async function run() {
);
case 'prettier':
return execaCommand(`pnpm prettier -c .`, { cwd, stdio: 'inherit' });
case 'published-types':
return lintPublishedTypes({ cwd });
case 'js:fix':
return execaCommand(
`pnpm eslint . ` + `--fix --cache --cache-strategy content`,
Expand All @@ -60,6 +63,76 @@ async function run() {
}
}

/**
* attw does not support wildcard entrypoints
*/
async function lintPublishedTypes({ cwd }) {
let manifest = await packageJson.read(cwd);
let name = manifest.name;

let entrypoints = [];

for (let [entryGlob, mapping] of Object.entries(manifest['exports'])) {
if (!entryGlob.includes('*')) {
let entry = path.join(name, entryGlob);

entrypoints.push(entry);
continue;
}

const files = globbySync(mapping.types.replace('*', '**/*'), { cwd });

// Map the files to full module paths
const mappedFiles = files.map((file) => {
// Now that we found files, we need to map them _back_ to entrypoints.
// Based on the entryGlob, we need to remove the path leading up until the '*',
let toRemove = mapping.types.split('*')[0];
let moduleName = file.split(toRemove)[1];

// we need to chop off the extension IFF the mapping.types includes it
if (mapping.types.endsWith('.d.ts')) {
moduleName = moduleName.replace('.d.ts', '');
}

return moduleName;
});

entrypoints.push(...mappedFiles);
}

entrypoints = entrypoints
// Remove stuff we are going to exclude
.filter((entry) => !entry.endsWith('addon-main'))
// Remove index files
.filter((entry) => !entry.endsWith('index'));

let args = [
'attw',
'--pack',
// This does not provide types
'--exclude-entrypoints',
'addon-main',
// We turn this one off because we don't care about CJS consumers
'--ignore-rules',
'cjs-resolves-to-esm',
// Wildcard is not official supported
'--ignore-rules',
'wildcard',
// publint will handle resolving
'--ignore-rules',
'internal-resolution-error',
'--include-entrypoints',
...entrypoints,
];

console.info(chalk.blueBright('Running:\n', args.join(' ')));

await execa('pnpm', args, {
cwd,
stdio: 'inherit',
});
}

function turbo(cmd) {
let args = [
'turbo',
Expand Down
1 change: 1 addition & 0 deletions dev/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"ember-apply": "^2.10.0",
"execa": "^7.2.0",
"fs-extra": "^11.1.1",
"globby": "^13.2.2",
"latest-version": "^7.0.0"
},
"engines": {
Expand Down
5 changes: 3 additions & 2 deletions ember-primitives/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"repository": "https://github.com/universal-ember/ember-primitives",
"license": "MIT",
"author": "nullvoxpopuli",
"type": "module",
"files": [
"addon-main.cjs",
"dist",
Expand All @@ -24,7 +25,7 @@
"lint:hbs": "pnpm -w exec lint hbs",
"lint:hbs:fix": "pnpm -w exec lint hbs:fix",
"lint:package": "pnpm publint",
"lint:published-types": "attw *.tgz || exit 0",
"lint:published-types": "pnpm -w exec lint published-types",
"lint:prettier:fix": "pnpm -w exec lint prettier:fix",
"lint:prettier": "pnpm -w exec lint prettier",
"lint:types": "glint",
Expand All @@ -33,7 +34,7 @@
"start:js": "rollup --config --watch",
"start:types": "glint --build --watch",
"test": "echo 'A v2 addon does not have tests, run tests in test-app'",
"prepack": "rollup --config"
"prepack": "pnpm build"
},
"dependencies": {
"@babel/runtime": "^7.22.6",
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

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