(spec: string)
| 106 | } |
| 107 | |
| 108 | async load(spec: string) { |
| 109 | const {config, lockfile} = this; |
| 110 | let body: Buffer; |
| 111 | if ( |
| 112 | spec.startsWith('-/') || |
| 113 | spec.startsWith('pin/') || |
| 114 | spec.startsWith('new/') || |
| 115 | spec.startsWith('error/') |
| 116 | ) { |
| 117 | body = (await this.remotePackageSDK.fetch(`/${spec}`)).body; |
| 118 | } else { |
| 119 | const [packageName, packagePath] = parsePackageImportSpecifier(spec); |
| 120 | if (lockfile && lockfile.dependencies[packageName]) { |
| 121 | const lockEntry = packageName + '#' + lockfile.dependencies[packageName]; |
| 122 | if (packagePath) { |
| 123 | body = ( |
| 124 | await this.remotePackageSDK.fetch('/' + lockfile.lock[lockEntry] + '/' + packagePath) |
| 125 | ).body; |
| 126 | } else { |
| 127 | body = (await this.remotePackageSDK.fetch('/' + lockfile.lock[lockEntry])).body; |
| 128 | } |
| 129 | } else { |
| 130 | const packageSemver = 'latest'; |
| 131 | logFetching( |
| 132 | (config.packageOptions as PackageOptionsRemote).origin, |
| 133 | packageName, |
| 134 | packageSemver, |
| 135 | ); |
| 136 | let lookupResponse = await this.remotePackageSDK.lookupBySpecifier(spec, packageSemver); |
| 137 | if (!lookupResponse.error && lookupResponse.importStatus === 'NEW') { |
| 138 | const buildResponse = await this.remotePackageSDK.buildNewPackage(spec, packageSemver); |
| 139 | if (!buildResponse.success) { |
| 140 | throw new Error('Package could not be built!'); |
| 141 | } |
| 142 | lookupResponse = await this.remotePackageSDK.lookupBySpecifier(spec, packageSemver); |
| 143 | } |
| 144 | if (lookupResponse.error) { |
| 145 | throw lookupResponse.error; |
| 146 | } |
| 147 | // Trigger a type fetch asynchronously. We want to resolve the JS as fast as possible, and |
| 148 | // the result of this is totally disconnected from the loading flow. |
| 149 | if (!existsSync(path.join(this.getCacheFolder(), '.snowpack/types', packageName))) { |
| 150 | this.remotePackageSDK |
| 151 | .installTypes( |
| 152 | packageName, |
| 153 | packageSemver, |
| 154 | path.join(this.getCacheFolder(), '.snowpack/types'), |
| 155 | ) |
| 156 | .catch(() => 'thats fine!'); |
| 157 | } |
| 158 | body = lookupResponse.body; |
| 159 | } |
| 160 | } |
| 161 | const ext = path.extname(spec); |
| 162 | if (!ext || isJavaScript(spec)) { |
| 163 | return { |
| 164 | contents: body |
| 165 | .toString() |
nothing calls this directly
no test coverage detected