MCPcopy Index your code
hub / github.com/ember-cli/ember-cli / import

Method import

lib/broccoli/ember-app.js:1099–1130  ·  view source on GitHub ↗

Imports an asset into the application. @public @method import @param {Object|String} asset Either a path to the asset or an object with environment names and paths as key-value pairs. @param {Object} [options] Options object @param {String} [options.type='vendor'] Either 'vendor

(asset, options)

Source from the content-addressed store, hash-verified

1097 @param {Array} [options.using] Specifies the array of transformations to be done on the asset. Can do an amd shim and/or custom transformation
1098 */
1099 import(asset, options) {
1100 let assetPath = this._getAssetPath(asset);
1101
1102 if (!assetPath) {
1103 return;
1104 }
1105
1106 options = defaultsDeep(options || {}, {
1107 type: 'vendor',
1108 prepend: false,
1109 });
1110
1111 let match = assetPath.match(/^node_modules\/((@[^/]+\/)?[^/]+)\//);
1112 if (match !== null) {
1113 let basedir = options.resolveFrom || this.project.root;
1114 let name = match[1];
1115 let _path = path.dirname(resolve.sync(`${name}/package.json`, { basedir }));
1116 this._nodeModules.set(_path, { name, path: _path });
1117 }
1118
1119 let directory = path.dirname(assetPath);
1120 let subdirectory = directory.replace(new RegExp(`^vendor/|node_modules/`), '');
1121 let extension = path.extname(assetPath);
1122
1123 if (!extension) {
1124 throw new Error(
1125 'You must pass a file to `app.import`. For directories specify them to the constructor under the `trees` option.'
1126 );
1127 }
1128
1129 this._import(assetPath, options, directory, subdirectory, extension);
1130 }
1131
1132 /**
1133 @private

Callers 6

importFunction · 0.80
ember-app-test.jsFile · 0.80
ember-cli-build.jsFile · 0.80
ember-cli-build.jsFile · 0.80
ember-cli-build.jsFile · 0.80
ember-cli-build.jsFile · 0.80

Calls 2

_getAssetPathMethod · 0.95
_importMethod · 0.95

Tested by

no test coverage detected