Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

♻️ Support absolute import paths #34264

Closed
wants to merge 16 commits into from
18 changes: 18 additions & 0 deletions build-system/babel-config/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,26 @@ function getReplaceGlobalsPlugin() {
];
}

/**
* Plugin config for import mapping (in compilation only, not browser).
* @return {!Array<string|Object>}
*/
function getImportResolverPlugin() {
return [
'module-resolver',
{
'root': ['.'],
'alias': {
'@': '.',
'@@': './src/core',
},
},
];
}

module.exports = {
getExperimentConstant,
getReplacePlugin,
getReplaceGlobalsPlugin,
getImportResolverPlugin,
};
2 changes: 2 additions & 0 deletions build-system/babel-config/minified-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'use strict';

const argv = require('minimist')(process.argv.slice(2));
const {getImportResolverPlugin} = require('./helpers');
const {getReplacePlugin} = require('./helpers');

/**
Expand All @@ -36,6 +37,7 @@ function getMinifiedConfig() {

const plugins = [
'optimize-objstr',
getImportResolverPlugin(),
'./build-system/babel-plugins/babel-plugin-transform-fix-leading-comments',
'./build-system/babel-plugins/babel-plugin-transform-promise-resolve',
'@babel/plugin-transform-react-constant-elements',
Expand Down
2 changes: 2 additions & 0 deletions build-system/babel-config/pre-closure-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'use strict';

const argv = require('minimist')(process.argv.slice(2));
const {getImportResolverPlugin} = require('./helpers');
const {getReplacePlugin} = require('./helpers');

/**
Expand All @@ -40,6 +41,7 @@ function getPreClosureConfig() {
const replacePlugin = getReplacePlugin();
const preClosurePlugins = [
'optimize-objstr',
getImportResolverPlugin(),
argv.coverage ? 'babel-plugin-istanbul' : null,
'./build-system/babel-plugins/babel-plugin-transform-fix-leading-comments',
'./build-system/babel-plugins/babel-plugin-transform-promise-resolve',
Expand Down
2 changes: 2 additions & 0 deletions build-system/babel-config/test-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
'use strict';

const argv = require('minimist')(process.argv.slice(2));
const {getImportResolverPlugin} = require('./helpers');
const {getReplacePlugin, getReplaceGlobalsPlugin} = require('./helpers');

/**
Expand Down Expand Up @@ -57,6 +58,7 @@ function getTestConfig() {
const replacePlugin = getReplacePlugin();
const replaceGlobalsPlugin = getReplaceGlobalsPlugin();
const testPlugins = [
getImportResolverPlugin(),
argv.coverage ? instanbulPlugin : null,
replacePlugin,
replaceGlobalsPlugin,
Expand Down
2 changes: 2 additions & 0 deletions build-system/babel-config/unminified-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ const argv = require('minimist')(process.argv.slice(2));
const {
VERSION: internalRuntimeVersion,
} = require('../compile/internal-version');
const {getImportResolverPlugin} = require('./helpers');
const {getReplacePlugin} = require('./helpers');

/**
Expand Down Expand Up @@ -49,6 +50,7 @@ function getUnminifiedConfig() {
];
const replacePlugin = getReplacePlugin();
const unminifiedPlugins = [
getImportResolverPlugin(),
argv.coverage ? 'babel-plugin-istanbul' : null,
replacePlugin,
'./build-system/babel-plugins/babel-plugin-transform-json-import',
Expand Down
4 changes: 4 additions & 0 deletions build-system/tasks/storybook/amp-env/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ module.exports = ({config}) => {
path.join(__dirname, '../node_modules'),
path.join(__dirname, '../../../../node_modules'),
],
alias: {
'@': path.join(__dirname, '../../../..'),
'@@': path.join(__dirname, '../../../../src/core'),
},
};
config.module = {
rules: [
Expand Down
2 changes: 2 additions & 0 deletions build-system/tasks/storybook/preact-env/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ module.exports = ({config}) => {
alias: {
'react': 'preact/compat',
'react-dom': 'preact/compat',
'@': path.join(__dirname, '../../../..'),
'@@': path.join(__dirname, '../../../../src/core'),
},
};
config.module = {
Expand Down
9 changes: 9 additions & 0 deletions jsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/*": ["./*"],
"@@/*": ["./src/core/*"]
}
}
}
88 changes: 88 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
"ava": "3.15.0",
"babel-plugin-istanbul": "6.0.0",
"babel-plugin-minify-replace": "0.5.0",
"babel-plugin-module-resolver": "4.1.0",
"babel-plugin-optimize-objstr": "1.0.0",
"baconipsum": "0.1.2",
"base62": "2.0.1",
Expand Down
8 changes: 4 additions & 4 deletions src/core/assert/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
* limitations under the License.
*/

import {elementStringOrPassThru} from '../error-message-helpers';
import {includes} from '../types/string';
import {isArray, isElement, isEnumValue, isString} from '../types';
import {remove} from '../types/array';
import {elementStringOrPassThru} from '@@/error-message-helpers';
import {includes} from '@@/types/string';
import {isArray, isElement, isEnumValue, isString} from '@@/types';
import {remove} from '@@/types/array';

/**
* @fileoverview This file provides the base implementation for assertion
Expand Down
2 changes: 1 addition & 1 deletion src/core/assert/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import * as assertions from './base';
import {isMinifiedMode} from '../minified-mode';
import {isMinifiedMode} from '@@/minified-mode';

/**
* @fileoverview This file provides the entrypoint for dev assertions. It's
Expand Down
2 changes: 1 addition & 1 deletion src/core/assert/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/

import * as assertions from './base';
import {USER_ERROR_SENTINEL} from '../error-message-helpers';
import {USER_ERROR_SENTINEL} from '@@/error-message-helpers';

/**
* @fileoverview This file provides the entrypoint for user assertions. It's
Expand Down
2 changes: 1 addition & 1 deletion src/core/constants/action-constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {pureDevAssert as devAssert} from '../assert';
import {pureDevAssert as devAssert} from '@@/assert';

/**
* Key string in an action arguments map for an unparsed object literal string.
Expand Down
4 changes: 2 additions & 2 deletions src/core/data-structures/signals.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
* limitations under the License.
*/

import {Deferred} from './promise';
import {map} from '../types/object';
import {Deferred} from '@@/data-structures/promise';
import {map} from '@@/types/object';

/**
* This object tracts signals and allows blocking until a signal has been
Expand Down
2 changes: 1 addition & 1 deletion src/core/dom/css.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

import {cssEscape} from '../../../third_party/css-escape/css-escape';
import {pureDevAssert as devAssert} from '../assert';
import {pureDevAssert as devAssert} from '@@/assert';

/**
* @type {boolean|undefined}
Expand Down
2 changes: 1 addition & 1 deletion src/core/error-message-helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {isElement} from './types';
import {isElement} from '@@/types';

/**
* Triple zero width space.
Expand Down
2 changes: 1 addition & 1 deletion test/unit/core/data-structures/test-lru-cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {LruCache} from '../../../../src/core/data-structures/lru-cache';
import {LruCache} from '@@/data-structures/lru-cache';

describes.sandboxed('LruCache', {}, () => {
let cache;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/core/data-structures/test-observable.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {Observable} from '../../../../src/core/data-structures/observable';
import {Observable} from '@@/data-structures/observable';

describes.sandboxed('Observable', {}, () => {
let observable;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/core/data-structures/test-priority-queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import PriorityQueue from '../../../../src/core/data-structures/priority-queue';
import PriorityQueue from '@@/data-structures/priority-queue';

describes.sandboxed('PriorityQueue', {}, () => {
let pq;
Expand Down
2 changes: 1 addition & 1 deletion test/unit/core/data-structures/test-promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import * as PromiseUtils from '../../../../src/core/data-structures/promise';
import * as PromiseUtils from '@@/data-structures/promise';

describes.sandboxed('PromiseUtils', {}, () => {
function getPromiseObject() {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/core/data-structures/test-signals.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {Signals} from '../../../../src/core/data-structures/signals';
import {Signals} from '@@/data-structures/signals';

describes.sandboxed('Signals', {}, (env) => {
let clock;
Expand Down
5 changes: 1 addition & 4 deletions test/unit/core/dom/test-css.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@
* limitations under the License.
*/

import {
escapeCssSelectorIdent,
prependSelectorsWith,
} from '../../../../src/core/dom/css';
import {escapeCssSelectorIdent, prependSelectorsWith} from '@@/dom/css';

describes.sandboxed('CSS', {}, () => {
describe('escapeCssSelectorIdent', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/unit/core/test-assert.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
* limitations under the License.
*/

import {USER_ERROR_SENTINEL} from '../../../src/core/error-message-helpers';
import {USER_ERROR_SENTINEL} from '@@/error-message-helpers';
import {
pureDevAssert as devAssert,
pureUserAssert as userAssert,
} from '../../../src/core/assert';
} from '@@/assert';

describes.sandboxed('assertions', {}, () => {
describe('devAssert', () => {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/core/test-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import {duplicateErrorIfNecessary, rethrowAsync} from '../../../src/core/error';
import {duplicateErrorIfNecessary, rethrowAsync} from '@@/error';
import {isUserErrorMessage, user} from '../../../src/log';

describes.sandboxed('errors', {}, () => {
Expand Down
Loading