Skip to content

Commit

Permalink
add v2 addon metadata
Browse files Browse the repository at this point in the history
This adds v2-addon-style metadata to the package.json at publication. Our build already produces everything needed to be a valid v2 addon, other than this metadata.

This PR doesn't actually flip the final switch though (by adding `version: 2` to the metdata). So it's safe and nonbreaking. This just gets us one step closer.

And it's helpful because embroider users will be able to opt in to treating ember-source as v2 even before we force it to be v2 for everyone.
  • Loading branch information
ef4 committed Sep 12, 2024
1 parent 669b94e commit 0909c98
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
8 changes: 7 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
"keywords": [
"ember-addon"
],
"exports": {
"./*": "./dist/packages/*",
"./dist/ember-template-compiler.js": "./dist/ember-template-compiler.js",
"./package.json": "./package.json"
},
"homepage": "https://emberjs.com/",
"bugs": {
"url": "https://github.com/emberjs/ember.js/issues"
Expand Down Expand Up @@ -174,7 +179,8 @@
"node": ">= 18.*"
},
"ember-addon": {
"after": "ember-cli-legacy-blueprints"
"after": "ember-cli-legacy-blueprints",
"type": "addon"
},
"typesVersions": {
"*": {
Expand Down
27 changes: 26 additions & 1 deletion rollup.config.mjs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { dirname, parse, resolve, join } from 'node:path';
import { existsSync, readFileSync, statSync } from 'node:fs';
import { existsSync, readFileSync, statSync, writeFileSync } from 'node:fs';
import { createRequire } from 'node:module';
import { fileURLToPath } from 'node:url';
import glob from 'glob';
Expand Down Expand Up @@ -71,6 +71,7 @@ function esmConfig() {
version(),
resolvePackages({ ...exposedDependencies(), ...hiddenDependencies() }),
pruneEmptyBundles(),
packageMeta(),
],
};
}
Expand Down Expand Up @@ -498,6 +499,30 @@ function pruneEmptyBundles() {
};
}

function packageMeta() {
let renamedModules = Object.fromEntries(
glob
.sync('**/*.js', { cwd: 'dist/packages', ignore: ['shared-chunks/**'], nodir: true })
.map((name) => {
return [name, 'ember-source/' + name];
})
);
return {
name: 'package-meta',
buildEnd(error) {
if (error) {
return;
}
let pkg = JSON.parse(readFileSync('package.json'));
if (!pkg['ember-addon']) {
pkg['ember-adodn'] = {};
}
pkg['ember-addon']['renamed-modules'] = renamedModules;
writeFileSync('package.json', JSON.stringify(pkg, null, 2));
},
};
}

function handleRollupWarnings(level, log, handler) {
switch (log.code) {
case 'CIRCULAR_DEPENDENCY':
Expand Down

0 comments on commit 0909c98

Please sign in to comment.