* @param {string} destination * @param {string} cwd * @returns {Promise }
(destination, cwd)
| 108 | * @returns {Promise<string>} |
| 109 | */ |
| 110 | async function copyWorkerScript(destination, cwd) { |
| 111 | // When running as a part of "postinstall" script, "cwd" equals the library's directory. |
| 112 | // The "postinstall" script resolves the right absolute public directory path. |
| 113 | const absolutePublicDir = toAbsolutePath(destination, cwd) |
| 114 | |
| 115 | if (!fs.existsSync(absolutePublicDir)) { |
| 116 | await fs.promises |
| 117 | .mkdir(absolutePublicDir, { recursive: true }) |
| 118 | .catch((error) => { |
| 119 | throw new Error( |
| 120 | invariant( |
| 121 | false, |
| 122 | 'Failed to copy the worker script at "%s": directory does not exist and could not be created.\nMake sure to include a relative path to the public directory of your application.\n\nSee the original error below:\n\n%s', |
| 123 | absolutePublicDir, |
| 124 | error, |
| 125 | ), |
| 126 | ) |
| 127 | }) |
| 128 | } |
| 129 | |
| 130 | // eslint-disable-next-line no-console |
| 131 | console.log('Copying the worker script at "%s"...', absolutePublicDir) |
| 132 | |
| 133 | const workerFilename = path.basename(SERVICE_WORKER_BUILD_PATH) |
| 134 | const workerDestinationPath = path.resolve(absolutePublicDir, workerFilename) |
| 135 | |
| 136 | fs.copyFileSync(SERVICE_WORKER_BUILD_PATH, workerDestinationPath) |
| 137 | |
| 138 | return workerDestinationPath |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * @param {Array<string>} paths |
no test coverage detected
searching dependent graphs…