Skip to content

Commit 16f9992

Browse files
authored
Use vite's built-in package.json loading to inline names and versions (#9494)
This eliminates the need for embroider macros to provide packages their own name and version. That is not a good use case for macros, since it can never change post-publication. The prepublication Vite build here has built-in support for this, and it does exactly what one would want, inlining only the strings that were imported from package.json. (Also, this is being motivated by the fact that addon-main.js in v2 addons in not guaranteed to be run by embroider. It's a classic file that does nothing under our Vite build. Having an alternative that allows apps (not addons) to manipulate the macros config is planned as a blocker for releasing the vite blueprint.) This PR is only a WIP, because I suspect the package publication process here needs to change to ensure that `vite build` gets run after each of the mirror package names and/or versions gets set. There's a lot going on in the publication step, so I figured it would be best to just open this for discussion first.
1 parent bb49391 commit 16f9992

File tree

4 files changed

+7
-25
lines changed

4 files changed

+7
-25
lines changed

packages/-ember-data/addon-main.cjs

-5
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,7 @@
33
const { addonShim } = require('@warp-drive/build-config/addon-shim.cjs');
44

55
const addon = addonShim(__dirname);
6-
addon.options = addon.options || {};
7-
addon.options['@embroider/macros'] = addon.options['@embroider/macros'] || {};
86
const pkg = require('./package.json');
9-
addon.options['@embroider/macros'].setOwnConfig = {
10-
VERSION: pkg.version,
11-
};
127
if (pkg['ember-addon'].version === 1) {
138
delete addon.treeForApp;
149
}

packages/-ember-data/src/version.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
1-
import { getOwnConfig } from '@embroider/macros';
2-
3-
const VERSION = getOwnConfig<{ VERSION: string }>().VERSION;
4-
export default VERSION;
1+
export { version as default } from '../package.json';

packages/core-types/addon-main.cjs

+1-10
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,4 @@
11
'use strict';
22

33
const { addonShim } = require('@warp-drive/build-config/addon-shim.cjs');
4-
const { version, name } = require('./package.json');
5-
6-
const addon = addonShim(__dirname);
7-
addon.options = addon.options || {};
8-
addon.options['@embroider/macros'] = addon.options['@embroider/macros'] || {};
9-
addon.options['@embroider/macros'].setOwnConfig = {
10-
PKG: { name, version },
11-
};
12-
13-
module.exports = addon;
4+
module.exports = addonShim(__dirname);

packages/core-types/src/-private.ts

+5-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// in testing mode, we utilize globals to ensure only one copy exists of
22
// these maps, due to bugs in ember-auto-import
3-
import { getOwnConfig } from '@embroider/macros';
4-
53
import { DEBUG, TESTING } from '@warp-drive/build-config/env';
64

5+
import { name, version } from '../package.json';
6+
77
type UniversalTransientKey =
88
// @ember-data/request
99
'REQ_ID';
@@ -118,12 +118,11 @@ const UniversalCache = (GlobalRef.__warpDrive_universalCache =
118118

119119
// in order to support mirror packages, we ensure that each
120120
// unique package name has its own global cache
121-
const PkgInfo = getOwnConfig<{ PKG: { name: string; version: string } }>().PKG;
122-
GlobalRef[PkgInfo.name] = GlobalRef[PkgInfo.name] ?? { __version: PkgInfo.version };
123-
const GlobalSink = GlobalRef[PkgInfo.name];
121+
GlobalRef[name] = GlobalRef[name] ?? { __version: version };
122+
const GlobalSink = GlobalRef[name];
124123

125124
if (DEBUG) {
126-
if (GlobalSink.__version !== PkgInfo.version) {
125+
if (GlobalSink.__version !== version) {
127126
throw new Error('Multiple versions of WarpDrive detected, the application will malfunction.');
128127
}
129128
}

0 commit comments

Comments
 (0)