diff --git a/src/commands/build.ts b/src/commands/build.ts index a4b34a6317..5319348d4c 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -228,6 +228,10 @@ export async function command(commandOptions: CommandOptions) { } const allBuiltFromFiles = new Set(); + + const webModulesScript = config.scripts.find(script => script.id === 'mount:web_modules'); + const webModulesLoc = webModulesScript ? webModulesScript.args.toUrl as string : '/web_modules'; + for (const workerConfig of relevantWorkers) { const {id, match, type} = workerConfig; if (type !== 'build' || match.length === 0) { @@ -317,7 +321,7 @@ export async function command(commandOptions: CommandOptions) { if (dependencyImportMap.imports[spec]) { let resolvedImport = path.posix.join( config.buildOptions.baseUrl, - `/web_modules`, + webModulesLoc, dependencyImportMap.imports[spec], ); const extName = path.extname(resolvedImport); @@ -337,7 +341,7 @@ export async function command(commandOptions: CommandOptions) { pkgName: missingPackageName, }, }); - return path.posix.join(config.buildOptions.baseUrl, `/web_modules`, `${spec}.js`); + return path.posix.join(config.buildOptions.baseUrl, webModulesLoc, `${spec}.js`); }); code = wrapImportMeta({code, env: true, hmr: false, config}); } diff --git a/src/commands/dev.ts b/src/commands/dev.ts index 6521081ad9..b9b7ba6ddd 100644 --- a/src/commands/dev.ts +++ b/src/commands/dev.ts @@ -287,6 +287,9 @@ export async function command(commandOptions: CommandOptions) { filesBeingBuilt.delete(fileLoc); } } + const webModulesScript = config.scripts.find(script => script.id === 'mount:web_modules'); + const webModulesLoc = webModulesScript ? webModulesScript.args.toUrl : '/web_modules'; + const ext = path.extname(fileLoc).substr(1); if (ext === 'js' || srcFileExtensionMapping[ext] === 'js') { let missingWebModule: {spec: string; pkgName: string} | null = null; @@ -319,7 +322,7 @@ export async function command(commandOptions: CommandOptions) { } if (dependencyImportMap.imports[spec]) { let resolvedImport = path.posix.resolve( - `/web_modules`, + webModulesLoc, dependencyImportMap.imports[spec], ); const extName = path.extname(resolvedImport); @@ -343,7 +346,7 @@ export async function command(commandOptions: CommandOptions) { if (extName && extName !== '.js') { spec = spec + '.proxy'; } - return `/web_modules/${spec}.js`; + return path.posix.join(webModulesLoc, `${spec}.js`); }); messageBus.emit('MISSING_WEB_MODULE', { diff --git a/src/config.ts b/src/config.ts index b586a837e4..43b007fb9f 100644 --- a/src/config.ts +++ b/src/config.ts @@ -316,6 +316,7 @@ function handleLegacyProxyScripts(config: any) { type RawScripts = Record; function normalizeScripts(cwd: string, scripts: RawScripts): BuildScript[] { + const dependenciesLoc = process.env.NODE_ENV === 'production' ? BUILD_DEPENDENCIES_DIR : DEV_DEPENDENCIES_DIR; const processedScripts: BuildScript[] = []; if (Object.keys(scripts).filter((k) => k.startsWith('bundle:')).length > 1) { handleConfigError(`scripts can only contain 1 script of type "bundle:".`); @@ -354,8 +355,15 @@ function normalizeScripts(cwd: string, scripts: RawScripts): BuildScript[] { `scripts[${scriptId}]: "--to ${to}" must be a URL path, and start with a "/"`, ); } - const dirDisk = cmdArr[0]; + let dirDisk = cmdArr[0]; const dirUrl = to || `/${cmdArr[0]}`; + + // mount:web_modules is a special case script where the fromDisk + // arg is harcoded to match the internal dependency dir + if (scriptId === 'mount:web_modules') { + dirDisk = dependenciesLoc; + } + newScriptConfig.args = { fromDisk: path.posix.normalize(dirDisk + '/'), toUrl: path.posix.normalize(dirUrl + '/'), @@ -379,15 +387,13 @@ function normalizeScripts(cwd: string, scripts: RawScripts): BuildScript[] { } if (!scripts['mount:web_modules']) { - const fromDisk = - process.env.NODE_ENV === 'production' ? BUILD_DEPENDENCIES_DIR : DEV_DEPENDENCIES_DIR; processedScripts.push({ id: 'mount:web_modules', type: 'mount', match: ['web_modules'], cmd: `mount $WEB_MODULES --to /web_modules`, args: { - fromDisk, + fromDisk: dependenciesLoc, toUrl: '/web_modules', }, }); diff --git a/test/build/custom-modules-dir/.gitignore b/test/build/custom-modules-dir/.gitignore new file mode 100644 index 0000000000..378eac25d3 --- /dev/null +++ b/test/build/custom-modules-dir/.gitignore @@ -0,0 +1 @@ +build diff --git a/test/build/custom-modules-dir/index.test.js b/test/build/custom-modules-dir/index.test.js new file mode 100644 index 0000000000..67608ccf7b --- /dev/null +++ b/test/build/custom-modules-dir/index.test.js @@ -0,0 +1,19 @@ +const fs = require('fs'); +const path = require('path'); +const execa = require('execa'); + +it('custom web_modules folder', () => { + execa.sync('npm', ['run', 'TEST'], { + cwd: __dirname, + // override NODE_ENV=test from jest, otherwise snowpack will assume + // development mode and try to copy from DEV_DEPENDENCIES_DIR + env: { NODE_ENV: 'production' } + }); + + // should write modules to the custom folder on disk + expect(fs.existsSync(path.join(__dirname, 'build', 'my_modules', 'array-flatten.js'))).toBe(true); + + // should rewrite path for web_modules imports + const outputJS = fs.readFileSync(path.resolve(__dirname, 'build', '_dist_', 'index.js'), 'utf8'); + expect(outputJS).toContain('/my_modules/array-flatten.js'); +}); diff --git a/test/build/custom-modules-dir/node_modules/array-flatten/LICENSE b/test/build/custom-modules-dir/node_modules/array-flatten/LICENSE new file mode 100644 index 0000000000..983fbe8aec --- /dev/null +++ b/test/build/custom-modules-dir/node_modules/array-flatten/LICENSE @@ -0,0 +1,21 @@ +The MIT License (MIT) + +Copyright (c) 2014 Blake Embrey (hello@blakeembrey.com) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/test/build/custom-modules-dir/node_modules/array-flatten/README.md b/test/build/custom-modules-dir/node_modules/array-flatten/README.md new file mode 100644 index 0000000000..d35e67bdf8 --- /dev/null +++ b/test/build/custom-modules-dir/node_modules/array-flatten/README.md @@ -0,0 +1,43 @@ +# Array Flatten + +[![NPM version][npm-image]][npm-url] +[![NPM downloads][downloads-image]][downloads-url] +[![Build status][travis-image]][travis-url] +[![Test coverage][coveralls-image]][coveralls-url] +[![Bundle size][bundlephobia-image]][bundlephobia-url] + +> Flatten nested arrays. + +## Installation + +``` +npm install array-flatten --save +``` + +## Usage + +```js +import { flatten } from "array-flatten"; + +flatten([1, [2, [3, [4, [5], 6], 7], 8], 9]); +//=> [1, 2, 3, 4, 5, 6, 7, 8, 9] + +(function() { + flatten(arguments); //=> [1, 2, 3] +})(1, [2, 3]); +``` + +## License + +MIT + +[npm-image]: https://img.shields.io/npm/v/array-flatten.svg?style=flat +[npm-url]: https://npmjs.org/package/array-flatten +[downloads-image]: https://img.shields.io/npm/dm/array-flatten.svg?style=flat +[downloads-url]: https://npmjs.org/package/array-flatten +[travis-image]: https://img.shields.io/travis/blakeembrey/array-flatten.svg?style=flat +[travis-url]: https://travis-ci.org/blakeembrey/array-flatten +[coveralls-image]: https://img.shields.io/coveralls/blakeembrey/array-flatten.svg?style=flat +[coveralls-url]: https://coveralls.io/r/blakeembrey/array-flatten?branch=master +[bundlephobia-image]: https://img.shields.io/bundlephobia/minzip/array-flatten.svg +[bundlephobia-url]: https://bundlephobia.com/result?p=array-flatten diff --git a/test/build/custom-modules-dir/node_modules/array-flatten/dist.es2015/index.js b/test/build/custom-modules-dir/node_modules/array-flatten/dist.es2015/index.js new file mode 100644 index 0000000000..a82b0460bc --- /dev/null +++ b/test/build/custom-modules-dir/node_modules/array-flatten/dist.es2015/index.js @@ -0,0 +1,23 @@ +/** + * Flatten an array indefinitely. + */ +export function flatten(array) { + var result = []; + $flatten(array, result); + return result; +} +/** + * Internal flatten function recursively passes `result`. + */ +function $flatten(array, result) { + for (var i = 0; i < array.length; i++) { + var value = array[i]; + if (Array.isArray(value)) { + $flatten(value, result); + } + else { + result.push(value); + } + } +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/test/build/custom-modules-dir/node_modules/array-flatten/dist.es2015/index.js.map b/test/build/custom-modules-dir/node_modules/array-flatten/dist.es2015/index.js.map new file mode 100644 index 0000000000..c49f36c2c5 --- /dev/null +++ b/test/build/custom-modules-dir/node_modules/array-flatten/dist.es2015/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA;;GAEG;AACH,MAAM,UAAU,OAAO,CAA2B,KAAQ;IACxD,IAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,QAAQ,CAAI,KAAK,EAAE,MAAM,CAAC,CAAC;IAC3B,OAAO,MAAM,CAAC;AAChB,CAAC;AAED;;GAEG;AACH,SAAS,QAAQ,CACf,KAAQ,EACR,MAAoB;IAEpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACrC,IAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAEvB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACxB,QAAQ,CAAC,KAAY,EAAE,MAAM,CAAC,CAAC;SAChC;aAAM;YACL,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACpB;KACF;AACH,CAAC","sourcesContent":["/**\n * Pick the value from an array.\n */\nexport type PickValue = T extends ReadonlyArray\n ? {\n [K in Extract]: PickValue;\n }[number]\n : T;\n\n/**\n * Flatten an `ArrayLike` object in TypeScript.\n */\nexport type FlatArray> = Array>;\n\n/**\n * Flatten an array indefinitely.\n */\nexport function flatten>(array: T): FlatArray {\n const result: FlatArray = [];\n $flatten(array, result);\n return result;\n}\n\n/**\n * Internal flatten function recursively passes `result`.\n */\nfunction $flatten>(\n array: T,\n result: FlatArray\n): void {\n for (let i = 0; i < array.length; i++) {\n const value = array[i];\n\n if (Array.isArray(value)) {\n $flatten(value as any, result);\n } else {\n result.push(value);\n }\n }\n}\n"]} \ No newline at end of file diff --git a/test/build/custom-modules-dir/node_modules/array-flatten/dist.es2015/index.spec.js b/test/build/custom-modules-dir/node_modules/array-flatten/dist.es2015/index.spec.js new file mode 100644 index 0000000000..bc275d0367 --- /dev/null +++ b/test/build/custom-modules-dir/node_modules/array-flatten/dist.es2015/index.spec.js @@ -0,0 +1,42 @@ +import { expectType } from "ts-expect"; +import { flatten } from "./index"; +describe("flatten", function () { + it("should flatten an array", function () { + var result = flatten([1, [2, [3, [4, [5]]], 6, [[7], 8], 9], 10]); + expectType(result); + expect(result).toStrictEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); + }); + it("should work with array-like", function () { + var result = flatten("test"); + expectType(result); + expect(result).toStrictEqual(["t", "e", "s", "t"]); + }); + it("should work with readonly array", function () { + var input = [1, [2, [3, [4]]]]; + var result = flatten(input); + expectType(result); + expect(result).toStrictEqual([1, 2, 3, 4]); + }); + it("should work with arguments", function () { + var input = (function () { + return arguments; + })(); + var result = flatten(input); + expectType(result); + expect(result).toStrictEqual([]); + }); + it("should work with mixed types", function () { + var fn = function (x) { return x; }; + var input = [1, ["test", [fn, [true]]]]; + var result = flatten(input); + expectType(result); + expect(result).toStrictEqual([1, "test", fn, true]); + }); + it("should work with tuples", function () { + var input = [1, [1, 2], [3]]; + var result = flatten(input); + expectType(result); + expect(result).toStrictEqual([1, 1, 2, 3]); + }); +}); +//# sourceMappingURL=index.spec.js.map \ No newline at end of file diff --git a/test/build/custom-modules-dir/node_modules/array-flatten/dist.es2015/index.spec.js.map b/test/build/custom-modules-dir/node_modules/array-flatten/dist.es2015/index.spec.js.map new file mode 100644 index 0000000000..3cf0329441 --- /dev/null +++ b/test/build/custom-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,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expectType } from \"ts-expect\";\nimport { flatten } from \"./index\";\n\ndescribe(\"flatten\", () => {\n it(\"should flatten an array\", () => {\n const result = flatten([1, [2, [3, [4, [5]]], 6, [[7], 8], 9], 10]);\n\n expectType(result);\n\n expect(result).toStrictEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);\n });\n\n it(\"should work with array-like\", () => {\n const result = flatten(\"test\");\n\n expectType(result);\n\n expect(result).toStrictEqual([\"t\", \"e\", \"s\", \"t\"]);\n });\n\n it(\"should work with readonly array\", () => {\n const input = [1, [2, [3, [4]]]] as const;\n const result = flatten(input);\n\n expectType<(1 | 2 | 3 | 4)[]>(result);\n\n expect(result).toStrictEqual([1, 2, 3, 4]);\n });\n\n it(\"should work with arguments\", () => {\n const input = (function() {\n return arguments;\n })();\n const result = flatten(input);\n\n expectType(result);\n\n expect(result).toStrictEqual([]);\n });\n\n it(\"should work with mixed types\", () => {\n const fn = (x: string) => x;\n const input = [1, [\"test\", [fn, [true]]]];\n const result = flatten(input);\n\n expectType<(number | string | boolean | typeof fn)[]>(result);\n\n expect(result).toStrictEqual([1, \"test\", fn, true]);\n });\n\n it(\"should work with tuples\", () => {\n const input: [number, [number, number], [number]] = [1, [1, 2], [3]];\n const result = flatten(input);\n\n expectType(result);\n\n expect(result).toStrictEqual([1, 1, 2, 3]);\n });\n});\n"]} \ No newline at end of file diff --git a/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.d.ts b/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.d.ts new file mode 100644 index 0000000000..14dff30600 --- /dev/null +++ b/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.d.ts @@ -0,0 +1,14 @@ +/** + * Pick the value from an array. + */ +export declare type PickValue = T extends ReadonlyArray ? { + [K in Extract]: PickValue; +}[number] : T; +/** + * Flatten an `ArrayLike` object in TypeScript. + */ +export declare type FlatArray> = Array>; +/** + * Flatten an array indefinitely. + */ +export declare function flatten>(array: T): FlatArray; diff --git a/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.js b/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.js new file mode 100644 index 0000000000..16c4911af1 --- /dev/null +++ b/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.js @@ -0,0 +1,26 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Flatten an array indefinitely. + */ +function flatten(array) { + var result = []; + $flatten(array, result); + return result; +} +exports.flatten = flatten; +/** + * Internal flatten function recursively passes `result`. + */ +function $flatten(array, result) { + for (var i = 0; i < array.length; i++) { + var value = array[i]; + if (Array.isArray(value)) { + $flatten(value, result); + } + else { + result.push(value); + } + } +} +//# sourceMappingURL=index.js.map \ No newline at end of file diff --git a/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.js.map b/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.js.map new file mode 100644 index 0000000000..3ab13a8dc1 --- /dev/null +++ b/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;AAcA;;GAEG;AACH,SAAgB,OAAO,CAA2B,KAAQ;IACxD,IAAM,MAAM,GAAiB,EAAE,CAAC;IAChC,QAAQ,CAAI,KAAK,EAAE,MAAM,CAAC,CAAC;IAC3B,OAAO,MAAM,CAAC;AAChB,CAAC;AAJD,0BAIC;AAED;;GAEG;AACH,SAAS,QAAQ,CACf,KAAQ,EACR,MAAoB;IAEpB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE;QACrC,IAAM,KAAK,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;QAEvB,IAAI,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE;YACxB,QAAQ,CAAC,KAAY,EAAE,MAAM,CAAC,CAAC;SAChC;aAAM;YACL,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;SACpB;KACF;AACH,CAAC","sourcesContent":["/**\n * Pick the value from an array.\n */\nexport type PickValue = T extends ReadonlyArray\n ? {\n [K in Extract]: PickValue;\n }[number]\n : T;\n\n/**\n * Flatten an `ArrayLike` object in TypeScript.\n */\nexport type FlatArray> = Array>;\n\n/**\n * Flatten an array indefinitely.\n */\nexport function flatten>(array: T): FlatArray {\n const result: FlatArray = [];\n $flatten(array, result);\n return result;\n}\n\n/**\n * Internal flatten function recursively passes `result`.\n */\nfunction $flatten>(\n array: T,\n result: FlatArray\n): void {\n for (let i = 0; i < array.length; i++) {\n const value = array[i];\n\n if (Array.isArray(value)) {\n $flatten(value as any, result);\n } else {\n result.push(value);\n }\n }\n}\n"]} \ No newline at end of file diff --git a/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.spec.d.ts b/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.spec.d.ts new file mode 100644 index 0000000000..cb0ff5c3b5 --- /dev/null +++ b/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.spec.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.spec.js b/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.spec.js new file mode 100644 index 0000000000..b5bf9b1d44 --- /dev/null +++ b/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.spec.js @@ -0,0 +1,44 @@ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +var ts_expect_1 = require("ts-expect"); +var index_1 = require("./index"); +describe("flatten", function () { + it("should flatten an array", function () { + var result = index_1.flatten([1, [2, [3, [4, [5]]], 6, [[7], 8], 9], 10]); + ts_expect_1.expectType(result); + expect(result).toStrictEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]); + }); + it("should work with array-like", function () { + var result = index_1.flatten("test"); + ts_expect_1.expectType(result); + expect(result).toStrictEqual(["t", "e", "s", "t"]); + }); + it("should work with readonly array", function () { + var input = [1, [2, [3, [4]]]]; + var result = index_1.flatten(input); + ts_expect_1.expectType(result); + expect(result).toStrictEqual([1, 2, 3, 4]); + }); + it("should work with arguments", function () { + var input = (function () { + return arguments; + })(); + var result = index_1.flatten(input); + ts_expect_1.expectType(result); + expect(result).toStrictEqual([]); + }); + it("should work with mixed types", function () { + var fn = function (x) { return x; }; + var input = [1, ["test", [fn, [true]]]]; + var result = index_1.flatten(input); + ts_expect_1.expectType(result); + expect(result).toStrictEqual([1, "test", fn, true]); + }); + it("should work with tuples", function () { + var input = [1, [1, 2], [3]]; + var result = index_1.flatten(input); + ts_expect_1.expectType(result); + expect(result).toStrictEqual([1, 1, 2, 3]); + }); +}); +//# sourceMappingURL=index.spec.js.map \ No newline at end of file diff --git a/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.spec.js.map b/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.spec.js.map new file mode 100644 index 0000000000..4d10f1dd36 --- /dev/null +++ b/test/build/custom-modules-dir/node_modules/array-flatten/dist/index.spec.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../src/index.spec.ts"],"names":[],"mappings":";;AAAA,uCAAuC;AACvC,iCAAkC;AAElC,QAAQ,CAAC,SAAS,EAAE;IAClB,EAAE,CAAC,yBAAyB,EAAE;QAC5B,IAAM,MAAM,GAAG,eAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC;QAEpE,sBAAU,CAAW,MAAM,CAAC,CAAC;QAE7B,MAAM,CAAC,MAAM,CAAC,CAAC,a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QAC5B,IAAM,KAAK,GAAG,CAAC,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;QAC1C,IAAM,MAAM,GAAG,eAAO,CAAC,KAAK,CAAC,CAAC;QAE9B,sBAAU,CAA4C,MAAM,CAAC,CAAC;QAE9D,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC;IACtD,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,yBAAyB,EAAE;QAC5B,IAAM,KAAK,GAAyC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;QACrE,IAAM,MAAM,GAAG,eAAO,CAAC,KAAK,CAAC,CAAC;QAE9B,sBAAU,CAAW,MAAM,CAAC,CAAC;QAE7B,MAAM,CAAC,MAAM,CAAC,CAAC,aAAa,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC","sourcesContent":["import { expectType } from \"ts-expect\";\nimport { flatten } from \"./index\";\n\ndescribe(\"flatten\", () => {\n it(\"should flatten an array\", () => {\n const result = flatten([1, [2, [3, [4, [5]]], 6, [[7], 8], 9], 10]);\n\n expectType(result);\n\n expect(result).toStrictEqual([1, 2, 3, 4, 5, 6, 7, 8, 9, 10]);\n });\n\n it(\"should work with array-like\", () => {\n const result = flatten(\"test\");\n\n expectType(result);\n\n expect(result).toStrictEqual([\"t\", \"e\", \"s\", \"t\"]);\n });\n\n it(\"should work with readonly array\", () => {\n const input = [1, [2, [3, [4]]]] as const;\n const result = flatten(input);\n\n expectType<(1 | 2 | 3 | 4)[]>(result);\n\n expect(result).toStrictEqual([1, 2, 3, 4]);\n });\n\n it(\"should work with arguments\", () => {\n const input = (function() {\n return arguments;\n })();\n const result = flatten(input);\n\n expectType(result);\n\n expect(result).toStrictEqual([]);\n });\n\n it(\"should work with mixed types\", () => {\n const fn = (x: string) => x;\n const input = [1, [\"test\", [fn, [true]]]];\n const result = flatten(input);\n\n expectType<(number | string | boolean | typeof fn)[]>(result);\n\n expect(result).toStrictEqual([1, \"test\", fn, true]);\n });\n\n it(\"should work with tuples\", () => {\n const input: [number, [number, number], [number]] = [1, [1, 2], [3]];\n const result = flatten(input);\n\n expectType(result);\n\n expect(result).toStrictEqual([1, 1, 2, 3]);\n });\n});\n"]} \ No newline at end of file diff --git a/test/build/custom-modules-dir/node_modules/array-flatten/package.json b/test/build/custom-modules-dir/node_modules/array-flatten/package.json new file mode 100644 index 0000000000..5a72db5154 --- /dev/null +++ b/test/build/custom-modules-dir/node_modules/array-flatten/package.json @@ -0,0 +1,126 @@ +{ + "_from": "array-flatten@^3.0.0", + "_id": "array-flatten@3.0.0", + "_inBundle": false, + "_integrity": "sha512-zPMVc3ZYlGLNk4mpK1NzP2wg0ml9t7fUgDsayR5Y5rSzxQilzR9FGu/EH2jQOcKSAeAfWeylyW8juy3OkWRvNA==", + "_location": "/array-flatten", + "_phantomChildren": {}, + "_requested": { + "type": "range", + "registry": true, + "raw": "array-flatten@^3.0.0", + "name": "array-flatten", + "escapedName": "array-flatten", + "rawSpec": "^3.0.0", + "saveSpec": null, + "fetchSpec": "^3.0.0" + }, + "_requiredBy": [ + "/" + ], + "_resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-3.0.0.tgz", + "_shasum": "6428ca2ee52c7b823192ec600fa3ed2f157cd541", + "_spec": "array-flatten@^3.0.0", + "_where": "/Users/dan/fork/snowpack/test/build/custom-modules-dir", + "author": { + "name": "Blake Embrey", + "email": "hello@blakeembrey.com", + "url": "http://blakeembrey.me" + }, + "bugs": { + "url": "https://github.com/blakeembrey/array-flatten/issues" + }, + "bundleDependencies": false, + "deprecated": false, + "description": "Flatten nested arrays", + "devDependencies": { + "@size-limit/preset-small-lib": "^2.2.1", + "@types/jest": "^24.0.23", + "@types/node": "^12.12.11", + "benchmarked": "^2.0.0", + "husky": "^3.1.0", + "jest": "^24.9.0", + "lint-staged": "^9.4.3", + "prettier": "^1.19.1", + "ts-expect": "^1.1.0", + "ts-jest": "^24.1.0", + "tslint": "^5.20.1", + "tslint-config-prettier": "^1.18.0", + "tslint-config-standard": "^9.0.0", + "typescript": "^3.7.2" + }, + "files": [ + "dist/", + "dist.es2015/", + "LICENSE" + ], + "homepage": "https://github.com/blakeembrey/array-flatten", + "husky": { + "hooks": { + "pre-commit": "lint-staged" + } + }, + "jest": { + "roots": [ + "/src/" + ], + "transform": { + "\\.tsx?$": "ts-jest" + }, + "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(tsx?|jsx?)$", + "moduleFileExtensions": [ + "ts", + "tsx", + "js", + "jsx", + "json", + "node" + ] + }, + "jsnext:main": "dist.es2015/index.js", + "keywords": [ + "array", + "flatten", + "arguments", + "depth", + "fast", + "for" + ], + "license": "MIT", + "lint-staged": { + "*.{js,json,css,md}": [ + "npm run prettier", + "git add" + ] + }, + "main": "dist/index.js", + "module": "dist.es2015/index.js", + "name": "array-flatten", + "publishConfig": { + "access": "public" + }, + "repository": { + "type": "git", + "url": "git://github.com/blakeembrey/array-flatten.git" + }, + "scripts": { + "benchmark": "node benchmark", + "build": "rimraf dist/ dist.es2015/ && tsc && tsc -P tsconfig.es2015.json", + "format": "npm run prettier -- \"{.,src/**,benchmark/**}/*.{js,ts}\"", + "lint": "tslint \"src/**/*\" --project tsconfig.json", + "prepare": "npm run build", + "prettier": "prettier --write", + "size": "size-limit", + "specs": "jest --coverage", + "test": "npm run build && npm run lint && npm run specs && npm run size" + }, + "sideEffects": false, + "size-limit": [ + { + "path": "dist/index.js", + "limit": "100 B" + } + ], + "typings": "dist/index.d.ts", + "version": "3.0.0" +} diff --git a/test/build/custom-modules-dir/package-lock.json b/test/build/custom-modules-dir/package-lock.json new file mode 100644 index 0000000000..5fc0d2ff4d --- /dev/null +++ b/test/build/custom-modules-dir/package-lock.json @@ -0,0 +1,11 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "array-flatten": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/array-flatten/-/array-flatten-3.0.0.tgz", + "integrity": "sha512-zPMVc3ZYlGLNk4mpK1NzP2wg0ml9t7fUgDsayR5Y5rSzxQilzR9FGu/EH2jQOcKSAeAfWeylyW8juy3OkWRvNA==" + } + } +} diff --git a/test/build/custom-modules-dir/package.json b/test/build/custom-modules-dir/package.json new file mode 100644 index 0000000000..0e74921042 --- /dev/null +++ b/test/build/custom-modules-dir/package.json @@ -0,0 +1,14 @@ +{ + "scripts": { + "TEST": "node ../../../pkg/dist-node/index.bin.js build" + }, + "snowpack": { + "scripts": { + "mount:src": "mount src --to /_dist_", + "mount:web_modules": "mount $WEB_MODULES --to /my_modules" + } + }, + "dependencies": { + "array-flatten": "^3.0.0" + } +} diff --git a/test/build/custom-modules-dir/src/index.js b/test/build/custom-modules-dir/src/index.js new file mode 100644 index 0000000000..2f851626fa --- /dev/null +++ b/test/build/custom-modules-dir/src/index.js @@ -0,0 +1,5 @@ +import {flatten} from 'array-flatten'; + +export default function doNothing() { + // I do nothing 🎉 +}