From d7fa9e18a534d328afee2bbbb4def43443d1d4bb Mon Sep 17 00:00:00 2001 From: "Fred K. Schott" Date: Thu, 18 Jun 2020 22:42:07 -0700 Subject: [PATCH] improve resolve logic --- src/commands/build-util.ts | 13 -- src/commands/build.ts | 7 +- src/commands/import-resolver.ts | 54 +++++--- .../expected-build/__snowpack__/env.js | 1 + .../expected-build/_dist_/components/index.js | 1 + .../_dist_/components/style.css | 1 + .../_dist_/components/style.css.proxy.js | 9 ++ .../expected-build/_dist_/index.js | 16 +++ .../expected-build/_dist_/sort.js | 1 + .../resolve-imports/expected-build/index.html | 20 +++ .../web_modules/array-flatten.js | 24 ++++ .../web_modules/import-map.json | 5 + .../node_modules/array-flatten/LICENSE | 21 +++ .../node_modules/array-flatten/README.md | 43 ++++++ .../array-flatten/dist.es2015/index.js | 23 ++++ .../array-flatten/dist.es2015/index.js.map | 1 + .../array-flatten/dist.es2015/index.spec.js | 42 ++++++ .../dist.es2015/index.spec.js.map | 1 + .../array-flatten/dist/index.d.ts | 14 ++ .../node_modules/array-flatten/dist/index.js | 26 ++++ .../array-flatten/dist/index.js.map | 1 + .../array-flatten/dist/index.spec.d.ts | 1 + .../array-flatten/dist/index.spec.js | 44 ++++++ .../array-flatten/dist/index.spec.js.map | 1 + .../node_modules/array-flatten/package.json | 129 ++++++++++++++++++ test/build/resolve-imports/package.json | 15 ++ test/build/resolve-imports/public/index.html | 20 +++ .../resolve-imports/src/components/index.js | 1 + .../resolve-imports/src/components/style.css | 1 + .../src/components/style.css.proxy.js | 9 ++ test/build/resolve-imports/src/index.js | 24 ++++ test/build/resolve-imports/src/sort.js | 1 + 32 files changed, 538 insertions(+), 32 deletions(-) create mode 100644 test/build/resolve-imports/expected-build/__snowpack__/env.js create mode 100644 test/build/resolve-imports/expected-build/_dist_/components/index.js create mode 100644 test/build/resolve-imports/expected-build/_dist_/components/style.css create mode 100644 test/build/resolve-imports/expected-build/_dist_/components/style.css.proxy.js create mode 100644 test/build/resolve-imports/expected-build/_dist_/index.js create mode 100644 test/build/resolve-imports/expected-build/_dist_/sort.js create mode 100644 test/build/resolve-imports/expected-build/index.html create mode 100644 test/build/resolve-imports/expected-build/web_modules/array-flatten.js create mode 100644 test/build/resolve-imports/expected-build/web_modules/import-map.json create mode 100644 test/build/resolve-imports/node_modules/array-flatten/LICENSE create mode 100644 test/build/resolve-imports/node_modules/array-flatten/README.md create mode 100644 test/build/resolve-imports/node_modules/array-flatten/dist.es2015/index.js create mode 100644 test/build/resolve-imports/node_modules/array-flatten/dist.es2015/index.js.map create mode 100644 test/build/resolve-imports/node_modules/array-flatten/dist.es2015/index.spec.js create mode 100644 test/build/resolve-imports/node_modules/array-flatten/dist.es2015/index.spec.js.map create mode 100644 test/build/resolve-imports/node_modules/array-flatten/dist/index.d.ts create mode 100644 test/build/resolve-imports/node_modules/array-flatten/dist/index.js create mode 100644 test/build/resolve-imports/node_modules/array-flatten/dist/index.js.map create mode 100644 test/build/resolve-imports/node_modules/array-flatten/dist/index.spec.d.ts create mode 100644 test/build/resolve-imports/node_modules/array-flatten/dist/index.spec.js create mode 100644 test/build/resolve-imports/node_modules/array-flatten/dist/index.spec.js.map create mode 100644 test/build/resolve-imports/node_modules/array-flatten/package.json create mode 100644 test/build/resolve-imports/package.json create mode 100644 test/build/resolve-imports/public/index.html create mode 100644 test/build/resolve-imports/src/components/index.js create mode 100644 test/build/resolve-imports/src/components/style.css create mode 100644 test/build/resolve-imports/src/components/style.css.proxy.js create mode 100644 test/build/resolve-imports/src/index.js create mode 100644 test/build/resolve-imports/src/sort.js diff --git a/src/commands/build-util.ts b/src/commands/build-util.ts index c205148347..82b06e024b 100644 --- a/src/commands/build-util.ts +++ b/src/commands/build-util.ts @@ -1,9 +1,7 @@ import type CSSModuleLoader from 'css-modules-loader-core'; import type {EventEmitter} from 'events'; import execa from 'execa'; -import {statSync} from 'fs'; import npmRunPath from 'npm-run-path'; -import path from 'path'; import { BuildScript, SnowpackConfig, @@ -16,17 +14,6 @@ export function checkIsPreact(filePath: string, contents: string) { return filePath.endsWith('.jsx') && IS_PREACT.test(contents); } -export function isDirectoryImport(fileLoc: string, spec: string): boolean { - const importedFileOnDisk = path.resolve(path.dirname(fileLoc), spec); - try { - const stat = statSync(importedFileOnDisk); - return stat.isDirectory(); - } catch (err) { - // file doesn't exist, that's fine - } - return false; -} - export function wrapImportMeta({ code, hmr, diff --git a/src/commands/build.ts b/src/commands/build.ts index 15677f11d3..9bd72d5ea3 100644 --- a/src/commands/build.ts +++ b/src/commands/build.ts @@ -291,8 +291,11 @@ export async function command(commandOptions: CommandOptions) { // We treat ".proxy.js" files special: we need to make sure that they exist on disk // in the final build, so we mark them to be written to disk at the next step. if (resolvedImportUrl.endsWith('.proxy.js')) { - const resolvedUrl = path.resolve(path.dirname(outPath), spec); - allProxiedFiles.add(resolvedUrl); + allProxiedFiles.add( + resolvedImportUrl.startsWith('/') + ? path.resolve(cwd, spec) + : path.resolve(path.dirname(outPath), spec), + ); } return resolvedImportUrl; } diff --git a/src/commands/import-resolver.ts b/src/commands/import-resolver.ts index 970bf6965a..bac626543d 100644 --- a/src/commands/import-resolver.ts +++ b/src/commands/import-resolver.ts @@ -1,9 +1,9 @@ +import {Stats, statSync} from 'fs'; import path from 'path'; import {SnowpackConfig} from '../config'; import {findMatchingMountScript} from '../util'; -import {isDirectoryImport} from './build-util'; import srcFileExtensionMapping from './src-file-extension-mapping'; - +const cwd = process.cwd(); const URL_HAS_PROTOCOL_REGEX = /^\w:\/\./; interface ImportResolverOptions { @@ -14,6 +14,36 @@ interface ImportResolverOptions { config: SnowpackConfig; } +/** Perform a file disk lookup for the requested import specifier. */ +export function getImportStats(dirLoc: string, spec: string): Stats | false { + const importedFileOnDisk = path.resolve(dirLoc, spec); + try { + return statSync(importedFileOnDisk); + } catch (err) { + // file doesn't exist, that's fine + } + return false; +} + +/** Resolve an import based on the state of the file/folder found on disk. */ +function resolveSourceSpecifier(spec: string, stats: Stats | false, isBundled: boolean) { + if (stats && stats.isDirectory()) { + spec = spec + '/index.js'; + } else if (!stats && !spec.endsWith('.js')) { + spec = spec + '.js'; + } + const ext = path.extname(spec).substr(1); + const extToReplace = srcFileExtensionMapping[ext]; + if (extToReplace) { + spec = spec.replace(new RegExp(`${ext}$`), extToReplace); + } + if (!isBundled && (extToReplace || ext) !== 'js') { + spec = spec + '.proxy.js'; + } + + return spec; +} + /** * Create a import resolver function, which converts any import relative to the given file at "fileLoc" * to a proper URL. Returns false if no matching import was found, which usually indicates a package @@ -36,24 +66,14 @@ export function createImportResolver({ let mountScript = findMatchingMountScript(config.scripts, spec); if (mountScript) { let {fromDisk, toUrl} = mountScript.args; + const importStats = getImportStats(cwd, spec); + spec = resolveSourceSpecifier(spec, importStats, isBundled); spec = spec.replace(fromDisk, toUrl); + return spec; } if (spec.startsWith('/') || spec.startsWith('./') || spec.startsWith('../')) { - const ext = path.extname(spec).substr(1); - if (!ext) { - if (isDirectoryImport(fileLoc, spec)) { - return spec + '/index.js'; - } else { - return spec + '.js'; - } - } - const extToReplace = srcFileExtensionMapping[ext]; - if (extToReplace) { - spec = spec.replace(new RegExp(`${ext}$`), extToReplace); - } - if (!isBundled && (extToReplace || ext) !== 'js') { - spec = spec + '.proxy.js'; - } + const importStats = getImportStats(path.dirname(fileLoc), spec); + spec = resolveSourceSpecifier(spec, importStats, isBundled); return spec; } if (dependencyImportMap.imports[spec]) { diff --git a/test/build/resolve-imports/expected-build/__snowpack__/env.js b/test/build/resolve-imports/expected-build/__snowpack__/env.js new file mode 100644 index 0000000000..fe1375eb2c --- /dev/null +++ b/test/build/resolve-imports/expected-build/__snowpack__/env.js @@ -0,0 +1 @@ +export default {"MODE":"production","NODE_ENV":"production"}; \ No newline at end of file diff --git a/test/build/resolve-imports/expected-build/_dist_/components/index.js b/test/build/resolve-imports/expected-build/_dist_/components/index.js new file mode 100644 index 0000000000..5be82f4971 --- /dev/null +++ b/test/build/resolve-imports/expected-build/_dist_/components/index.js @@ -0,0 +1 @@ +export default "Button"; diff --git a/test/build/resolve-imports/expected-build/_dist_/components/style.css b/test/build/resolve-imports/expected-build/_dist_/components/style.css new file mode 100644 index 0000000000..d35818c9e0 --- /dev/null +++ b/test/build/resolve-imports/expected-build/_dist_/components/style.css @@ -0,0 +1 @@ +body { color: red } \ No newline at end of file diff --git a/test/build/resolve-imports/expected-build/_dist_/components/style.css.proxy.js b/test/build/resolve-imports/expected-build/_dist_/components/style.css.proxy.js new file mode 100644 index 0000000000..4dd76ac102 --- /dev/null +++ b/test/build/resolve-imports/expected-build/_dist_/components/style.css.proxy.js @@ -0,0 +1,9 @@ + +const code = "body { color: red }"; + +const styleEl = document.createElement("style"); +const codeEl = document.createTextNode(code); +styleEl.type = 'text/css'; + +styleEl.appendChild(codeEl); +document.head.appendChild(styleEl); \ No newline at end of file diff --git a/test/build/resolve-imports/expected-build/_dist_/index.js b/test/build/resolve-imports/expected-build/_dist_/index.js new file mode 100644 index 0000000000..a98dd8869d --- /dev/null +++ b/test/build/resolve-imports/expected-build/_dist_/index.js @@ -0,0 +1,16 @@ +import {flatten} from "/web_modules/array-flatten.js"; +console.log(flatten); +import sort2 from "./sort.js"; +import sort_ from "/_dist_/sort.js"; +import sort__ from "/_dist_/sort.js"; +console.log(sort2, sort_, sort__); +import components2 from "./components/index.js"; +import components_ from "./components/index.js"; +import components__ from "./components/index.js"; +import components___ from "/_dist_/components/index.js"; +import components____ from "/_dist_/components/index.js"; +import components_____ from "/_dist_/components/index.js"; +console.log(components2, components_, components__, components___, components____, components_____); +import styles from "./components/style.css.proxy.js"; +import styles_ from "/_dist_/components/style.css.proxy.js"; +console.log(styles, styles_); diff --git a/test/build/resolve-imports/expected-build/_dist_/sort.js b/test/build/resolve-imports/expected-build/_dist_/sort.js new file mode 100644 index 0000000000..73fe028029 --- /dev/null +++ b/test/build/resolve-imports/expected-build/_dist_/sort.js @@ -0,0 +1 @@ +export default (arr) => arr.sort(); diff --git a/test/build/resolve-imports/expected-build/index.html b/test/build/resolve-imports/expected-build/index.html new file mode 100644 index 0000000000..7d097fe8e5 --- /dev/null +++ b/test/build/resolve-imports/expected-build/index.html @@ -0,0 +1,20 @@ + + + + + + + Snowpack App + + + + + + \ No newline at end of file diff --git a/test/build/resolve-imports/expected-build/web_modules/array-flatten.js b/test/build/resolve-imports/expected-build/web_modules/array-flatten.js new file mode 100644 index 0000000000..1cc2d53af8 --- /dev/null +++ b/test/build/resolve-imports/expected-build/web_modules/array-flatten.js @@ -0,0 +1,24 @@ +/** + * Flatten an array indefinitely. + */ +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); + } + } +} + +export { flatten }; diff --git a/test/build/resolve-imports/expected-build/web_modules/import-map.json b/test/build/resolve-imports/expected-build/web_modules/import-map.json new file mode 100644 index 0000000000..704b8ba214 --- /dev/null +++ b/test/build/resolve-imports/expected-build/web_modules/import-map.json @@ -0,0 +1,5 @@ +{ + "imports": { + "array-flatten": "./array-flatten.js" + } +} \ No newline at end of file diff --git a/test/build/resolve-imports/node_modules/array-flatten/LICENSE b/test/build/resolve-imports/node_modules/array-flatten/LICENSE new file mode 100644 index 0000000000..983fbe8aec --- /dev/null +++ b/test/build/resolve-imports/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/resolve-imports/node_modules/array-flatten/README.md b/test/build/resolve-imports/node_modules/array-flatten/README.md new file mode 100644 index 0000000000..d35e67bdf8 --- /dev/null +++ b/test/build/resolve-imports/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/resolve-imports/node_modules/array-flatten/dist.es2015/index.js b/test/build/resolve-imports/node_modules/array-flatten/dist.es2015/index.js new file mode 100644 index 0000000000..a82b0460bc --- /dev/null +++ b/test/build/resolve-imports/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/resolve-imports/node_modules/array-flatten/dist.es2015/index.js.map b/test/build/resolve-imports/node_modules/array-flatten/dist.es2015/index.js.map new file mode 100644 index 0000000000..c49f36c2c5 --- /dev/null +++ b/test/build/resolve-imports/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/resolve-imports/node_modules/array-flatten/dist.es2015/index.spec.js b/test/build/resolve-imports/node_modules/array-flatten/dist.es2015/index.spec.js new file mode 100644 index 0000000000..bc275d0367 --- /dev/null +++ b/test/build/resolve-imports/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/resolve-imports/node_modules/array-flatten/dist.es2015/index.spec.js.map b/test/build/resolve-imports/node_modules/array-flatten/dist.es2015/index.spec.js.map new file mode 100644 index 0000000000..3cf0329441 --- /dev/null +++ b/test/build/resolve-imports/node_modules/array-flatten/dist.es2015/index.spec.js.map @@ -0,0 +1 @@ +{"version":3,"file":"index.spec.js","sourceRoot":"","sources":["../src/index.spec.ts"],"names":[],"mappings":"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","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/resolve-imports/node_modules/array-flatten/dist/index.d.ts b/test/build/resolve-imports/node_modules/array-flatten/dist/index.d.ts new file mode 100644 index 0000000000..14dff30600 --- /dev/null +++ b/test/build/resolve-imports/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/resolve-imports/node_modules/array-flatten/dist/index.js b/test/build/resolve-imports/node_modules/array-flatten/dist/index.js new file mode 100644 index 0000000000..16c4911af1 --- /dev/null +++ b/test/build/resolve-imports/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/resolve-imports/node_modules/array-flatten/dist/index.js.map b/test/build/resolve-imports/node_modules/array-flatten/dist/index.js.map new file mode 100644 index 0000000000..3ab13a8dc1 --- /dev/null +++ b/test/build/resolve-imports/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/resolve-imports/node_modules/array-flatten/dist/index.spec.d.ts b/test/build/resolve-imports/node_modules/array-flatten/dist/index.spec.d.ts new file mode 100644 index 0000000000..cb0ff5c3b5 --- /dev/null +++ b/test/build/resolve-imports/node_modules/array-flatten/dist/index.spec.d.ts @@ -0,0 +1 @@ +export {}; diff --git a/test/build/resolve-imports/node_modules/array-flatten/dist/index.spec.js b/test/build/resolve-imports/node_modules/array-flatten/dist/index.spec.js new file mode 100644 index 0000000000..b5bf9b1d44 --- /dev/null +++ b/test/build/resolve-imports/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/resolve-imports/node_modules/array-flatten/dist/index.spec.js.map b/test/build/resolve-imports/node_modules/array-flatten/dist/index.spec.js.map new file mode 100644 index 0000000000..4d10f1dd36 --- /dev/null +++ b/test/build/resolve-imports/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":"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","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/resolve-imports/node_modules/array-flatten/package.json b/test/build/resolve-imports/node_modules/array-flatten/package.json new file mode 100644 index 0000000000..880d57e0fc --- /dev/null +++ b/test/build/resolve-imports/node_modules/array-flatten/package.json @@ -0,0 +1,129 @@ +{ + "_args": [ + [ + "array-flatten@3.0.0", + "/Users/dan/fork/snowpack/test/build/base-url" + ] + ], + "_from": "array-flatten@3.0.0", + "_id": "array-flatten@3.0.0", + "_inBundle": false, + "_integrity": "sha512-zPMVc3ZYlGLNk4mpK1NzP2wg0ml9t7fUgDsayR5Y5rSzxQilzR9FGu/EH2jQOcKSAeAfWeylyW8juy3OkWRvNA==", + "_location": "/array-flatten", + "_phantomChildren": {}, + "_requested": { + "type": "version", + "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", + "_spec": "3.0.0", + "_where": "/Users/dan/fork/snowpack/test/build/base-url", + "author": { + "name": "Blake Embrey", + "email": "hello@blakeembrey.com", + "url": "http://blakeembrey.me" + }, + "bugs": { + "url": "https://github.com/blakeembrey/array-flatten/issues" + }, + "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/resolve-imports/package.json b/test/build/resolve-imports/package.json new file mode 100644 index 0000000000..1ecd1a706f --- /dev/null +++ b/test/build/resolve-imports/package.json @@ -0,0 +1,15 @@ +{ + "scripts": { + "start": "node ../../../pkg/dist-node/index.bin.js dev", + "TEST": "node ../../../pkg/dist-node/index.bin.js build" + }, + "snowpack": { + "scripts": { + "mount:public": "mount public --to /", + "mount:src": "mount src --to /_dist_" + } + }, + "dependencies": { + "array-flatten": "^3.0.0" + } +} \ No newline at end of file diff --git a/test/build/resolve-imports/public/index.html b/test/build/resolve-imports/public/index.html new file mode 100644 index 0000000000..32f493caaa --- /dev/null +++ b/test/build/resolve-imports/public/index.html @@ -0,0 +1,20 @@ + + + + + + + Snowpack App + + + + + + \ No newline at end of file diff --git a/test/build/resolve-imports/src/components/index.js b/test/build/resolve-imports/src/components/index.js new file mode 100644 index 0000000000..9596a50e1c --- /dev/null +++ b/test/build/resolve-imports/src/components/index.js @@ -0,0 +1 @@ +export default 'Button'; \ No newline at end of file diff --git a/test/build/resolve-imports/src/components/style.css b/test/build/resolve-imports/src/components/style.css new file mode 100644 index 0000000000..d35818c9e0 --- /dev/null +++ b/test/build/resolve-imports/src/components/style.css @@ -0,0 +1 @@ +body { color: red } \ No newline at end of file diff --git a/test/build/resolve-imports/src/components/style.css.proxy.js b/test/build/resolve-imports/src/components/style.css.proxy.js new file mode 100644 index 0000000000..4dd76ac102 --- /dev/null +++ b/test/build/resolve-imports/src/components/style.css.proxy.js @@ -0,0 +1,9 @@ + +const code = "body { color: red }"; + +const styleEl = document.createElement("style"); +const codeEl = document.createTextNode(code); +styleEl.type = 'text/css'; + +styleEl.appendChild(codeEl); +document.head.appendChild(styleEl); \ No newline at end of file diff --git a/test/build/resolve-imports/src/index.js b/test/build/resolve-imports/src/index.js new file mode 100644 index 0000000000..ca6e0b5c56 --- /dev/null +++ b/test/build/resolve-imports/src/index.js @@ -0,0 +1,24 @@ +// Path aliases +import {flatten} from 'array-flatten'; +console.log(flatten); + +// Importing a file +import sort from './sort'; // relative import +import sort_ from 'src/sort'; // bare import using mount +import sort__ from 'src/sort.js'; // bare import using mount + extension +console.log(sort, sort_, sort__); + +// Importing a directory index.js file +import components from './components'; // relative import +import components_ from './components/index'; // relative import with index appended +import components__ from './components/index.js'; // relative import with index appended +import components___ from 'src/components'; // bare import using mount +import components____ from 'src/components/index'; // bare import using mount and index appended +import components_____ from 'src/components/index.js'; // bare import using mount and index.js appended +console.log(components, components_, components__, components___, components____, components_____); + + +// Importing something that isn't JS +import styles from './components/style.css'; // relative import +import styles_ from 'src/components/style.css'; // relative import +console.log(styles, styles_); \ No newline at end of file diff --git a/test/build/resolve-imports/src/sort.js b/test/build/resolve-imports/src/sort.js new file mode 100644 index 0000000000..73fe028029 --- /dev/null +++ b/test/build/resolve-imports/src/sort.js @@ -0,0 +1 @@ +export default (arr) => arr.sort();