1 | import { getName, quoteId } from '../utils/map-helpers.js';
|
2 | import getInteropBlock from './shared/getInteropBlock.js';
|
3 | import getExportBlock from './shared/getExportBlock.js';
|
4 |
|
5 | export default function amd ( bundle, magicString, { exportMode, indentString }, options ) {
|
6 | let deps = bundle.externalModules.map( quoteId );
|
7 | let args = bundle.externalModules.map( getName );
|
8 |
|
9 | if ( exportMode === 'named' ) {
|
10 | args.unshift( `exports` );
|
11 | deps.unshift( `'exports'` );
|
12 | }
|
13 |
|
14 | const params =
|
15 | ( options.moduleId ? `'${options.moduleId}', ` : `` ) +
|
16 | ( deps.length ? `[${deps.join( ', ' )}], ` : `` );
|
17 |
|
18 | const useStrict = options.useStrict !== false ? ` 'use strict';` : ``;
|
19 | const intro = `define(${params}function (${args.join( ', ' )}) {${useStrict}\n\n`;
|
20 |
|
21 |
|
22 | const interopBlock = getInteropBlock( bundle );
|
23 | if ( interopBlock ) magicString.prepend( interopBlock + '\n\n' );
|
24 |
|
25 | const exportBlock = getExportBlock( bundle.entryModule, exportMode );
|
26 | if ( exportBlock ) magicString.append( '\n\n' + exportBlock );
|
27 |
|
28 | return magicString
|
29 | .indent( indentString )
|
30 | .append( '\n\n});' )
|
31 | .prepend( intro );
|
32 | }
|