diff --git a/dev/bin/lint.js b/dev/bin/lint.js index c9f5b3155..e0f68420d 100755 --- a/dev/bin/lint.js +++ b/dev/bin/lint.js @@ -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 @@ -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`, @@ -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', diff --git a/dev/package.json b/dev/package.json index 446249f13..48eb22659 100644 --- a/dev/package.json +++ b/dev/package.json @@ -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": { diff --git a/ember-primitives/package.json b/ember-primitives/package.json index 0975daf44..084fa27c1 100644 --- a/ember-primitives/package.json +++ b/ember-primitives/package.json @@ -8,6 +8,7 @@ "repository": "https://github.com/universal-ember/ember-primitives", "license": "MIT", "author": "nullvoxpopuli", + "type": "module", "files": [ "addon-main.cjs", "dist", @@ -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", @@ -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", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a2baa2bc4..1a2b78c24 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -53,6 +53,9 @@ importers: fs-extra: specifier: ^11.1.1 version: 11.1.1 + globby: + specifier: ^13.2.2 + version: 13.2.2 latest-version: specifier: ^7.0.0 version: 7.0.0