@vscode/chat-lib 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (391) hide show
  1. package/dist/src/_internal/extension/xtab/common/promptCrafting.d.ts.map +1 -1
  2. package/dist/src/_internal/extension/xtab/common/promptCrafting.js +6 -5
  3. package/dist/src/_internal/extension/xtab/common/promptCrafting.js.map +1 -1
  4. package/dist/src/_internal/platform/configuration/common/configurationService.d.ts +1 -0
  5. package/dist/src/_internal/platform/configuration/common/configurationService.d.ts.map +1 -1
  6. package/dist/src/_internal/platform/configuration/common/configurationService.js +1 -0
  7. package/dist/src/_internal/platform/configuration/common/configurationService.js.map +1 -1
  8. package/dist/src/_internal/platform/env/common/envService.d.ts +5 -0
  9. package/dist/src/_internal/platform/env/common/envService.d.ts.map +1 -1
  10. package/dist/src/_internal/platform/env/common/envService.js +2 -1
  11. package/dist/src/_internal/platform/env/common/envService.js.map +1 -1
  12. package/dist/src/_internal/platform/env/common/nullEnvService.d.ts +3 -0
  13. package/dist/src/_internal/platform/env/common/nullEnvService.d.ts.map +1 -1
  14. package/dist/src/_internal/platform/env/common/nullEnvService.js +8 -1
  15. package/dist/src/_internal/platform/env/common/nullEnvService.js.map +1 -1
  16. package/dist/src/_internal/platform/telemetry/common/nullExperimentationService.d.ts +7 -0
  17. package/dist/src/_internal/platform/telemetry/common/nullExperimentationService.d.ts.map +1 -1
  18. package/dist/src/_internal/platform/telemetry/common/nullExperimentationService.js +1 -0
  19. package/dist/src/_internal/platform/telemetry/common/nullExperimentationService.js.map +1 -1
  20. package/dist/src/_internal/util/common/test/shims/chatTypes.d.ts +8 -0
  21. package/dist/src/_internal/util/common/test/shims/chatTypes.d.ts.map +1 -1
  22. package/dist/src/_internal/util/common/test/shims/chatTypes.js +19 -1
  23. package/dist/src/_internal/util/common/test/shims/chatTypes.js.map +1 -1
  24. package/dist/src/_internal/util/common/test/shims/vscodeTypesShim.d.ts.map +1 -1
  25. package/dist/src/_internal/util/common/test/shims/vscodeTypesShim.js +8 -1
  26. package/dist/src/_internal/util/common/test/shims/vscodeTypesShim.js.map +1 -1
  27. package/dist/src/_internal/vscodeTypes.d.ts +4 -0
  28. package/dist/src/_internal/vscodeTypes.d.ts.map +1 -1
  29. package/dist/src/_internal/vscodeTypes.js +5 -1
  30. package/dist/src/_internal/vscodeTypes.js.map +1 -1
  31. package/dist/src/main.d.ts +5 -0
  32. package/dist/src/main.d.ts.map +1 -1
  33. package/dist/src/main.js +12 -0
  34. package/dist/src/main.js.map +1 -1
  35. package/dist/src/package.json +46 -19
  36. package/package.json +3 -6
  37. package/src/_internal/extension/byok/node/openAIEndpoint.ts +0 -171
  38. package/src/_internal/extension/common/constants.ts +0 -90
  39. package/src/_internal/extension/inlineEdits/common/delayer.ts +0 -108
  40. package/src/_internal/extension/inlineEdits/common/editRebase.ts +0 -268
  41. package/src/_internal/extension/inlineEdits/common/ghNearbyNesProvider.tsx +0 -163
  42. package/src/_internal/extension/inlineEdits/common/nearbyCursorInlineEditProvider.ts +0 -225
  43. package/src/_internal/extension/inlineEdits/common/rejectionCollector.ts +0 -164
  44. package/src/_internal/extension/inlineEdits/node/debugRecorder.ts +0 -205
  45. package/src/_internal/extension/inlineEdits/node/importFiltering.ts +0 -25
  46. package/src/_internal/extension/inlineEdits/node/nesConfigs.ts +0 -12
  47. package/src/_internal/extension/inlineEdits/node/nextEditCache.ts +0 -278
  48. package/src/_internal/extension/inlineEdits/node/nextEditProvider.ts +0 -778
  49. package/src/_internal/extension/inlineEdits/node/nextEditProviderTelemetry.ts +0 -983
  50. package/src/_internal/extension/inlineEdits/node/nextEditResult.ts +0 -40
  51. package/src/_internal/extension/prompt/common/importStatement.ts +0 -25
  52. package/src/_internal/extension/prompt/node/chatMLFetcher.ts +0 -706
  53. package/src/_internal/extension/prompts/node/inline/summarizedDocument/fragments.ts +0 -146
  54. package/src/_internal/extension/prompts/node/inline/summarizedDocument/implementation.ts +0 -527
  55. package/src/_internal/extension/prompts/node/inline/summarizedDocument/projectedText.ts +0 -76
  56. package/src/_internal/extension/prompts/node/inline/visualization.ts +0 -65
  57. package/src/_internal/extension/vscode.proposed.activeComment.d.ts +0 -23
  58. package/src/_internal/extension/vscode.proposed.aiRelatedInformation.d.ts +0 -49
  59. package/src/_internal/extension/vscode.proposed.aiSettingsSearch.d.ts +0 -31
  60. package/src/_internal/extension/vscode.proposed.aiTextSearchProvider.d.ts +0 -41
  61. package/src/_internal/extension/vscode.proposed.authLearnMore.d.ts +0 -16
  62. package/src/_internal/extension/vscode.proposed.chatBinaryReferenceData.d.ts +0 -41
  63. package/src/_internal/extension/vscode.proposed.chatEditing.d.ts +0 -29
  64. package/src/_internal/extension/vscode.proposed.chatParticipantAdditions.d.ts +0 -636
  65. package/src/_internal/extension/vscode.proposed.chatParticipantPrivate.d.ts +0 -276
  66. package/src/_internal/extension/vscode.proposed.chatProvider.d.ts +0 -62
  67. package/src/_internal/extension/vscode.proposed.chatReadonlyPromptReference.d.ts +0 -17
  68. package/src/_internal/extension/vscode.proposed.chatReferenceDiagnostic.d.ts +0 -23
  69. package/src/_internal/extension/vscode.proposed.chatSessionsProvider.d.ts +0 -218
  70. package/src/_internal/extension/vscode.proposed.chatStatusItem.d.ts +0 -61
  71. package/src/_internal/extension/vscode.proposed.codeActionAI.d.ts +0 -16
  72. package/src/_internal/extension/vscode.proposed.commentReveal.d.ts +0 -32
  73. package/src/_internal/extension/vscode.proposed.contribCommentThreadAdditionalMenu.d.ts +0 -8
  74. package/src/_internal/extension/vscode.proposed.contribCommentsViewThreadMenus.d.ts +0 -6
  75. package/src/_internal/extension/vscode.proposed.contribSourceControlInputBoxMenu.d.ts +0 -7
  76. package/src/_internal/extension/vscode.proposed.dataChannels.d.ts +0 -19
  77. package/src/_internal/extension/vscode.proposed.defaultChatParticipant.d.ts +0 -52
  78. package/src/_internal/extension/vscode.proposed.documentFiltersExclusive.d.ts +0 -13
  79. package/src/_internal/extension/vscode.proposed.embeddings.d.ts +0 -33
  80. package/src/_internal/extension/vscode.proposed.extensionsAny.d.ts +0 -40
  81. package/src/_internal/extension/vscode.proposed.findFiles2.d.ts +0 -125
  82. package/src/_internal/extension/vscode.proposed.findTextInFiles.d.ts +0 -104
  83. package/src/_internal/extension/vscode.proposed.findTextInFiles2.d.ts +0 -144
  84. package/src/_internal/extension/vscode.proposed.inlineCompletionsAdditions.d.ts +0 -202
  85. package/src/_internal/extension/vscode.proposed.interactive.d.ts +0 -11
  86. package/src/_internal/extension/vscode.proposed.languageModelCapabilities.d.ts +0 -25
  87. package/src/_internal/extension/vscode.proposed.languageModelDataPart.d.ts +0 -163
  88. package/src/_internal/extension/vscode.proposed.languageModelSystem.d.ts +0 -17
  89. package/src/_internal/extension/vscode.proposed.languageModelThinkingPart.d.ts +0 -49
  90. package/src/_internal/extension/vscode.proposed.languageModelToolResultAudience.d.ts +0 -36
  91. package/src/_internal/extension/vscode.proposed.mappedEditsProvider.d.ts +0 -110
  92. package/src/_internal/extension/vscode.proposed.newSymbolNamesProvider.d.ts +0 -47
  93. package/src/_internal/extension/vscode.proposed.readonlyMessage.d.ts +0 -14
  94. package/src/_internal/extension/vscode.proposed.resolvers.d.ts +0 -475
  95. package/src/_internal/extension/vscode.proposed.scmInputBoxValueProvider.d.ts +0 -25
  96. package/src/_internal/extension/vscode.proposed.taskProblemMatcherStatus.d.ts +0 -42
  97. package/src/_internal/extension/vscode.proposed.terminalDataWriteEvent.d.ts +0 -32
  98. package/src/_internal/extension/vscode.proposed.terminalExecuteCommandEvent.d.ts +0 -48
  99. package/src/_internal/extension/vscode.proposed.terminalQuickFixProvider.d.ts +0 -87
  100. package/src/_internal/extension/vscode.proposed.terminalSelection.d.ts +0 -16
  101. package/src/_internal/extension/vscode.proposed.testObserver.d.ts +0 -199
  102. package/src/_internal/extension/vscode.proposed.textDocumentChangeReason.d.ts +0 -30
  103. package/src/_internal/extension/vscode.proposed.textSearchProvider.d.ts +0 -281
  104. package/src/_internal/extension/vscode.proposed.textSearchProvider2.d.ts +0 -297
  105. package/src/_internal/extension/xtab/common/promptCrafting.ts +0 -670
  106. package/src/_internal/extension/xtab/node/xtabEndpoint.ts +0 -102
  107. package/src/_internal/extension/xtab/node/xtabProvider.ts +0 -976
  108. package/src/_internal/extension/xtab/node/xtabUtils.ts +0 -62
  109. package/src/_internal/platform/authentication/common/authentication.ts +0 -309
  110. package/src/_internal/platform/authentication/common/copilotToken.ts +0 -300
  111. package/src/_internal/platform/authentication/common/copilotTokenManager.ts +0 -59
  112. package/src/_internal/platform/authentication/common/copilotTokenStore.ts +0 -40
  113. package/src/_internal/platform/authentication/common/staticGitHubAuthenticationService.ts +0 -96
  114. package/src/_internal/platform/authentication/node/copilotTokenManager.ts +0 -303
  115. package/src/_internal/platform/chat/common/chatMLFetcher.ts +0 -124
  116. package/src/_internal/platform/chat/common/chatQuotaService.ts +0 -63
  117. package/src/_internal/platform/chat/common/chatQuotaServiceImpl.ts +0 -96
  118. package/src/_internal/platform/chat/common/commonTypes.ts +0 -353
  119. package/src/_internal/platform/chat/common/conversationOptions.ts +0 -16
  120. package/src/_internal/platform/chat/common/globalStringUtils.ts +0 -54
  121. package/src/_internal/platform/chat/common/interactionService.ts +0 -35
  122. package/src/_internal/platform/configuration/common/configurationService.ts +0 -803
  123. package/src/_internal/platform/configuration/common/defaultsOnlyConfigurationService.ts +0 -39
  124. package/src/_internal/platform/configuration/common/jsonSchema.ts +0 -139
  125. package/src/_internal/platform/configuration/common/validator.ts +0 -242
  126. package/src/_internal/platform/diff/common/diffService.ts +0 -41
  127. package/src/_internal/platform/diff/common/diffWorker.ts +0 -83
  128. package/src/_internal/platform/diff/node/diffServiceImpl.ts +0 -85
  129. package/src/_internal/platform/editing/common/abstractText.ts +0 -177
  130. package/src/_internal/platform/editing/common/notebookDocumentSnapshot.ts +0 -122
  131. package/src/_internal/platform/editing/common/positionOffsetTransformer.ts +0 -202
  132. package/src/_internal/platform/editing/common/textDocumentSnapshot.ts +0 -274
  133. package/src/_internal/platform/endpoint/common/capiClient.ts +0 -37
  134. package/src/_internal/platform/endpoint/common/chatModelCapabilities.ts +0 -115
  135. package/src/_internal/platform/endpoint/common/domainService.ts +0 -27
  136. package/src/_internal/platform/endpoint/common/endpointProvider.ts +0 -104
  137. package/src/_internal/platform/endpoint/common/endpointTypes.ts +0 -12
  138. package/src/_internal/platform/endpoint/common/licenseAgreement.ts +0 -11
  139. package/src/_internal/platform/endpoint/common/statefulMarkerContainer.tsx +0 -85
  140. package/src/_internal/platform/endpoint/common/thinkingDataContainer.tsx +0 -44
  141. package/src/_internal/platform/endpoint/node/capiClientImpl.ts +0 -18
  142. package/src/_internal/platform/endpoint/node/chatEndpoint.ts +0 -435
  143. package/src/_internal/platform/endpoint/node/domainServiceImpl.ts +0 -80
  144. package/src/_internal/platform/endpoint/node/proxyXtabEndpoint.ts +0 -43
  145. package/src/_internal/platform/endpoint/node/responsesApi.ts +0 -326
  146. package/src/_internal/platform/env/common/envService.ts +0 -134
  147. package/src/_internal/platform/env/common/nullEnvService.ts +0 -68
  148. package/src/_internal/platform/env/common/packagejson.ts +0 -49
  149. package/src/_internal/platform/git/common/gitExtensionService.ts +0 -21
  150. package/src/_internal/platform/git/common/nullGitExtensionService.ts +0 -20
  151. package/src/_internal/platform/git/vscode/git.d.ts +0 -414
  152. package/src/_internal/platform/github/common/githubAPI.ts +0 -44
  153. package/src/_internal/platform/github/common/githubService.ts +0 -87
  154. package/src/_internal/platform/github/common/nullOctokitServiceImpl.ts +0 -21
  155. package/src/_internal/platform/ignore/common/ignoreService.ts +0 -72
  156. package/src/_internal/platform/inlineCompletions/common/api.ts +0 -198
  157. package/src/_internal/platform/inlineEdits/common/dataTypes/diagnosticData.ts +0 -32
  158. package/src/_internal/platform/inlineEdits/common/dataTypes/documentId.ts +0 -52
  159. package/src/_internal/platform/inlineEdits/common/dataTypes/edit.ts +0 -165
  160. package/src/_internal/platform/inlineEdits/common/dataTypes/editUtils.ts +0 -74
  161. package/src/_internal/platform/inlineEdits/common/dataTypes/fetchCancellationError.ts +0 -14
  162. package/src/_internal/platform/inlineEdits/common/dataTypes/languageContext.ts +0 -107
  163. package/src/_internal/platform/inlineEdits/common/dataTypes/languageId.ts +0 -14
  164. package/src/_internal/platform/inlineEdits/common/dataTypes/permutation.ts +0 -69
  165. package/src/_internal/platform/inlineEdits/common/dataTypes/rootedLineEdit.ts +0 -49
  166. package/src/_internal/platform/inlineEdits/common/dataTypes/textEditLength.ts +0 -74
  167. package/src/_internal/platform/inlineEdits/common/dataTypes/textEditLengthHelper/combineTextEditInfos.ts +0 -132
  168. package/src/_internal/platform/inlineEdits/common/dataTypes/textEditLengthHelper/length.ts +0 -184
  169. package/src/_internal/platform/inlineEdits/common/dataTypes/textEditLengthHelper/textEditInfo.ts +0 -32
  170. package/src/_internal/platform/inlineEdits/common/dataTypes/xtabPromptOptions.ts +0 -89
  171. package/src/_internal/platform/inlineEdits/common/debugRecorderBookmark.ts +0 -10
  172. package/src/_internal/platform/inlineEdits/common/editReason.ts +0 -134
  173. package/src/_internal/platform/inlineEdits/common/inlineEditLogContext.ts +0 -490
  174. package/src/_internal/platform/inlineEdits/common/observableGit.ts +0 -49
  175. package/src/_internal/platform/inlineEdits/common/observableWorkspace.ts +0 -239
  176. package/src/_internal/platform/inlineEdits/common/responseProcessor.ts +0 -249
  177. package/src/_internal/platform/inlineEdits/common/statelessNextEditProvider.ts +0 -468
  178. package/src/_internal/platform/inlineEdits/common/statelessNextEditProviders.ts +0 -59
  179. package/src/_internal/platform/inlineEdits/common/utils/observable.ts +0 -54
  180. package/src/_internal/platform/inlineEdits/common/utils/stringifyChatMessages.ts +0 -29
  181. package/src/_internal/platform/inlineEdits/common/utils/utils.ts +0 -56
  182. package/src/_internal/platform/inlineEdits/common/workspaceEditTracker/historyContextProvider.ts +0 -60
  183. package/src/_internal/platform/inlineEdits/common/workspaceEditTracker/nesHistoryContextProvider.ts +0 -353
  184. package/src/_internal/platform/inlineEdits/common/workspaceEditTracker/nesXtabHistoryTracker.ts +0 -176
  185. package/src/_internal/platform/languageContextProvider/common/languageContextProviderService.ts +0 -25
  186. package/src/_internal/platform/languageContextProvider/common/nullLanguageContextProviderService.ts +0 -38
  187. package/src/_internal/platform/languageServer/common/languageContextService.ts +0 -186
  188. package/src/_internal/platform/languages/common/languageDiagnosticsService.ts +0 -67
  189. package/src/_internal/platform/languages/common/testLanguageDiagnosticsService.ts +0 -28
  190. package/src/_internal/platform/log/common/logService.ts +0 -232
  191. package/src/_internal/platform/nesFetch/common/completionsAPI.ts +0 -78
  192. package/src/_internal/platform/nesFetch/common/completionsFetchService.ts +0 -118
  193. package/src/_internal/platform/nesFetch/common/responseStream.ts +0 -151
  194. package/src/_internal/platform/nesFetch/node/completionsFetchServiceImpl.ts +0 -236
  195. package/src/_internal/platform/nesFetch/node/streamTransformer.ts +0 -95
  196. package/src/_internal/platform/networking/common/fetch.ts +0 -349
  197. package/src/_internal/platform/networking/common/fetcherService.ts +0 -84
  198. package/src/_internal/platform/networking/common/networking.ts +0 -442
  199. package/src/_internal/platform/networking/common/openai.ts +0 -273
  200. package/src/_internal/platform/networking/node/chatStream.ts +0 -137
  201. package/src/_internal/platform/networking/node/stream.ts +0 -749
  202. package/src/_internal/platform/notebook/common/alternativeContent.ts +0 -89
  203. package/src/_internal/platform/notebook/common/alternativeContentFormat.ts +0 -10
  204. package/src/_internal/platform/notebook/common/alternativeContentProvider.json.ts +0 -262
  205. package/src/_internal/platform/notebook/common/alternativeContentProvider.text.ts +0 -243
  206. package/src/_internal/platform/notebook/common/alternativeContentProvider.ts +0 -41
  207. package/src/_internal/platform/notebook/common/alternativeContentProvider.xml.ts +0 -205
  208. package/src/_internal/platform/notebook/common/alternativeNotebookDocument.ts +0 -155
  209. package/src/_internal/platform/notebook/common/helpers.ts +0 -212
  210. package/src/_internal/platform/notebook/common/notebookService.ts +0 -43
  211. package/src/_internal/platform/openai/node/fetch.ts +0 -596
  212. package/src/_internal/platform/parser/node/nodes.ts +0 -190
  213. package/src/_internal/platform/requestLogger/node/nullRequestLogger.ts +0 -26
  214. package/src/_internal/platform/requestLogger/node/requestLogger.ts +0 -383
  215. package/src/_internal/platform/simulationTestContext/common/simulationTestContext.ts +0 -29
  216. package/src/_internal/platform/snippy/common/snippyService.ts +0 -25
  217. package/src/_internal/platform/telemetry/common/nullExperimentationService.ts +0 -64
  218. package/src/_internal/platform/telemetry/common/nullTelemetryService.ts +0 -53
  219. package/src/_internal/platform/telemetry/common/telemetry.ts +0 -215
  220. package/src/_internal/platform/telemetry/common/telemetryData.ts +0 -205
  221. package/src/_internal/platform/thinking/common/thinking.ts +0 -61
  222. package/src/_internal/platform/thinking/common/thinkingUtils.ts +0 -57
  223. package/src/_internal/platform/tokenizer/node/parseTikTokens.ts +0 -23
  224. package/src/_internal/platform/tokenizer/node/tikTokenizerImpl.ts +0 -74
  225. package/src/_internal/platform/tokenizer/node/tikTokenizerWorker.ts +0 -24
  226. package/src/_internal/platform/tokenizer/node/tokenizer.ts +0 -357
  227. package/src/_internal/platform/workspace/common/workspaceService.ts +0 -226
  228. package/src/_internal/platform/workspaceRecorder/common/workspaceLog.ts +0 -118
  229. package/src/_internal/util/common/anomalyDetection.ts +0 -112
  230. package/src/_internal/util/common/arrays.ts +0 -81
  231. package/src/_internal/util/common/async.ts +0 -155
  232. package/src/_internal/util/common/cache.ts +0 -183
  233. package/src/_internal/util/common/crypto.ts +0 -41
  234. package/src/_internal/util/common/errors.ts +0 -22
  235. package/src/_internal/util/common/globals.d.ts +0 -12
  236. package/src/_internal/util/common/imageUtils.ts +0 -154
  237. package/src/_internal/util/common/languages.ts +0 -940
  238. package/src/_internal/util/common/notebooks.ts +0 -286
  239. package/src/_internal/util/common/result.ts +0 -71
  240. package/src/_internal/util/common/services.ts +0 -43
  241. package/src/_internal/util/common/test/shims/chatTypes.ts +0 -448
  242. package/src/_internal/util/common/test/shims/editing.ts +0 -233
  243. package/src/_internal/util/common/test/shims/enums.ts +0 -61
  244. package/src/_internal/util/common/test/shims/l10n.ts +0 -37
  245. package/src/_internal/util/common/test/shims/newSymbolName.ts +0 -23
  246. package/src/_internal/util/common/test/shims/terminal.ts +0 -33
  247. package/src/_internal/util/common/test/shims/vscodeTypesShim.ts +0 -115
  248. package/src/_internal/util/common/time.ts +0 -31
  249. package/src/_internal/util/common/tokenizer.ts +0 -30
  250. package/src/_internal/util/common/tracing.ts +0 -52
  251. package/src/_internal/util/common/types.ts +0 -33
  252. package/src/_internal/util/common/variableLengthQuantity.ts +0 -40
  253. package/src/_internal/util/node/worker.ts +0 -130
  254. package/src/_internal/util/vs/base/common/arrays.ts +0 -926
  255. package/src/_internal/util/vs/base/common/arraysFind.ts +0 -206
  256. package/src/_internal/util/vs/base/common/assert.ts +0 -89
  257. package/src/_internal/util/vs/base/common/async.ts +0 -2582
  258. package/src/_internal/util/vs/base/common/buffer.ts +0 -501
  259. package/src/_internal/util/vs/base/common/cache.ts +0 -122
  260. package/src/_internal/util/vs/base/common/cancellation.ts +0 -150
  261. package/src/_internal/util/vs/base/common/charCode.ts +0 -452
  262. package/src/_internal/util/vs/base/common/codicons.ts +0 -66
  263. package/src/_internal/util/vs/base/common/codiconsLibrary.ts +0 -618
  264. package/src/_internal/util/vs/base/common/codiconsUtil.ts +0 -30
  265. package/src/_internal/util/vs/base/common/collections.ts +0 -156
  266. package/src/_internal/util/vs/base/common/diff/diff.ts +0 -1317
  267. package/src/_internal/util/vs/base/common/diff/diffChange.ts +0 -62
  268. package/src/_internal/util/vs/base/common/equals.ts +0 -148
  269. package/src/_internal/util/vs/base/common/errors.ts +0 -342
  270. package/src/_internal/util/vs/base/common/event.ts +0 -1782
  271. package/src/_internal/util/vs/base/common/extpath.ts +0 -425
  272. package/src/_internal/util/vs/base/common/filters.ts +0 -928
  273. package/src/_internal/util/vs/base/common/functional.ts +0 -34
  274. package/src/_internal/util/vs/base/common/glob.ts +0 -839
  275. package/src/_internal/util/vs/base/common/hash.ts +0 -326
  276. package/src/_internal/util/vs/base/common/htmlContent.ts +0 -212
  277. package/src/_internal/util/vs/base/common/iconLabels.ts +0 -118
  278. package/src/_internal/util/vs/base/common/iterator.ts +0 -196
  279. package/src/_internal/util/vs/base/common/lazy.ts +0 -59
  280. package/src/_internal/util/vs/base/common/lifecycle.ts +0 -845
  281. package/src/_internal/util/vs/base/common/linkedList.ts +0 -144
  282. package/src/_internal/util/vs/base/common/map.ts +0 -954
  283. package/src/_internal/util/vs/base/common/marshallingIds.ts +0 -35
  284. package/src/_internal/util/vs/base/common/mime.ts +0 -136
  285. package/src/_internal/util/vs/base/common/naturalLanguage/korean.ts +0 -425
  286. package/src/_internal/util/vs/base/common/network.ts +0 -429
  287. package/src/_internal/util/vs/base/common/numbers.ts +0 -166
  288. package/src/_internal/util/vs/base/common/objects.ts +0 -242
  289. package/src/_internal/util/vs/base/common/observable.ts +0 -10
  290. package/src/_internal/util/vs/base/common/observableInternal/base.ts +0 -208
  291. package/src/_internal/util/vs/base/common/observableInternal/changeTracker.ts +0 -96
  292. package/src/_internal/util/vs/base/common/observableInternal/commonFacade/cancellation.ts +0 -9
  293. package/src/_internal/util/vs/base/common/observableInternal/commonFacade/deps.ts +0 -12
  294. package/src/_internal/util/vs/base/common/observableInternal/debugLocation.ts +0 -88
  295. package/src/_internal/util/vs/base/common/observableInternal/debugName.ts +0 -150
  296. package/src/_internal/util/vs/base/common/observableInternal/experimental/utils.ts +0 -62
  297. package/src/_internal/util/vs/base/common/observableInternal/index.ts +0 -61
  298. package/src/_internal/util/vs/base/common/observableInternal/logging/consoleObservableLogger.ts +0 -388
  299. package/src/_internal/util/vs/base/common/observableInternal/logging/debugger/debuggerApi.d.ts +0 -154
  300. package/src/_internal/util/vs/base/common/observableInternal/logging/debugger/debuggerRpc.ts +0 -80
  301. package/src/_internal/util/vs/base/common/observableInternal/logging/debugger/devToolsLogger.ts +0 -485
  302. package/src/_internal/util/vs/base/common/observableInternal/logging/debugger/rpc.ts +0 -103
  303. package/src/_internal/util/vs/base/common/observableInternal/logging/debugger/utils.ts +0 -69
  304. package/src/_internal/util/vs/base/common/observableInternal/logging/logging.ts +0 -133
  305. package/src/_internal/util/vs/base/common/observableInternal/map.ts +0 -81
  306. package/src/_internal/util/vs/base/common/observableInternal/observables/baseObservable.ts +0 -172
  307. package/src/_internal/util/vs/base/common/observableInternal/observables/constObservable.ts +0 -44
  308. package/src/_internal/util/vs/base/common/observableInternal/observables/derived.ts +0 -190
  309. package/src/_internal/util/vs/base/common/observableInternal/observables/derivedImpl.ts +0 -445
  310. package/src/_internal/util/vs/base/common/observableInternal/observables/lazyObservableValue.ts +0 -154
  311. package/src/_internal/util/vs/base/common/observableInternal/observables/observableFromEvent.ts +0 -174
  312. package/src/_internal/util/vs/base/common/observableInternal/observables/observableSignal.ts +0 -67
  313. package/src/_internal/util/vs/base/common/observableInternal/observables/observableSignalFromEvent.ts +0 -62
  314. package/src/_internal/util/vs/base/common/observableInternal/observables/observableValue.ts +0 -131
  315. package/src/_internal/util/vs/base/common/observableInternal/observables/observableValueOpts.ts +0 -37
  316. package/src/_internal/util/vs/base/common/observableInternal/reactions/autorun.ts +0 -188
  317. package/src/_internal/util/vs/base/common/observableInternal/reactions/autorunImpl.ts +0 -256
  318. package/src/_internal/util/vs/base/common/observableInternal/set.ts +0 -78
  319. package/src/_internal/util/vs/base/common/observableInternal/transaction.ts +0 -115
  320. package/src/_internal/util/vs/base/common/observableInternal/utils/promise.ts +0 -129
  321. package/src/_internal/util/vs/base/common/observableInternal/utils/runOnChange.ts +0 -65
  322. package/src/_internal/util/vs/base/common/observableInternal/utils/utils.ts +0 -281
  323. package/src/_internal/util/vs/base/common/observableInternal/utils/utilsCancellation.ts +0 -101
  324. package/src/_internal/util/vs/base/common/observableInternal/utils/valueWithChangeEvent.ts +0 -31
  325. package/src/_internal/util/vs/base/common/path.ts +0 -1591
  326. package/src/_internal/util/vs/base/common/platform.ts +0 -282
  327. package/src/_internal/util/vs/base/common/process.ts +0 -78
  328. package/src/_internal/util/vs/base/common/resources.ts +0 -446
  329. package/src/_internal/util/vs/base/common/sequence.ts +0 -36
  330. package/src/_internal/util/vs/base/common/sseParser.ts +0 -247
  331. package/src/_internal/util/vs/base/common/stopwatch.ts +0 -43
  332. package/src/_internal/util/vs/base/common/stream.ts +0 -792
  333. package/src/_internal/util/vs/base/common/strings.ts +0 -1364
  334. package/src/_internal/util/vs/base/common/symbols.ts +0 -11
  335. package/src/_internal/util/vs/base/common/themables.ts +0 -106
  336. package/src/_internal/util/vs/base/common/types.ts +0 -345
  337. package/src/_internal/util/vs/base/common/uint.ts +0 -61
  338. package/src/_internal/util/vs/base/common/uri.ts +0 -752
  339. package/src/_internal/util/vs/base/common/uuid.ts +0 -72
  340. package/src/_internal/util/vs/base-common.d.ts +0 -42
  341. package/src/_internal/util/vs/editor/common/core/editOperation.ts +0 -62
  342. package/src/_internal/util/vs/editor/common/core/edits/edit.ts +0 -399
  343. package/src/_internal/util/vs/editor/common/core/edits/lineEdit.ts +0 -414
  344. package/src/_internal/util/vs/editor/common/core/edits/stringEdit.ts +0 -568
  345. package/src/_internal/util/vs/editor/common/core/edits/textEdit.ts +0 -411
  346. package/src/_internal/util/vs/editor/common/core/position.ts +0 -186
  347. package/src/_internal/util/vs/editor/common/core/range.ts +0 -519
  348. package/src/_internal/util/vs/editor/common/core/ranges/lineRange.ts +0 -416
  349. package/src/_internal/util/vs/editor/common/core/ranges/offsetRange.ts +0 -275
  350. package/src/_internal/util/vs/editor/common/core/text/abstractText.ts +0 -127
  351. package/src/_internal/util/vs/editor/common/core/text/positionToOffset.ts +0 -26
  352. package/src/_internal/util/vs/editor/common/core/text/positionToOffsetImpl.ts +0 -144
  353. package/src/_internal/util/vs/editor/common/core/text/textLength.ts +0 -150
  354. package/src/_internal/util/vs/editor/common/core/wordHelper.ts +0 -177
  355. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/algorithms/diffAlgorithm.ts +0 -210
  356. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/algorithms/dynamicProgrammingDiffing.ts +0 -109
  357. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/algorithms/myersDiffAlgorithm.ts +0 -178
  358. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/computeMovedLines.ts +0 -331
  359. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/defaultLinesDiffComputer.ts +0 -273
  360. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/heuristicSequenceOptimizations.ts +0 -475
  361. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/lineSequence.ts +0 -47
  362. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/linesSliceCharSequence.ts +0 -248
  363. package/src/_internal/util/vs/editor/common/diff/defaultLinesDiffComputer/utils.ts +0 -76
  364. package/src/_internal/util/vs/editor/common/diff/legacyLinesDiffComputer.ts +0 -693
  365. package/src/_internal/util/vs/editor/common/diff/linesDiffComputer.ts +0 -61
  366. package/src/_internal/util/vs/editor/common/diff/rangeMapping.ts +0 -418
  367. package/src/_internal/util/vs/editor/common/model/prefixSumComputer.ts +0 -304
  368. package/src/_internal/util/vs/nls.messages.ts +0 -21
  369. package/src/_internal/util/vs/nls.ts +0 -243
  370. package/src/_internal/util/vs/platform/instantiation/common/descriptors.ts +0 -23
  371. package/src/_internal/util/vs/platform/instantiation/common/graph.ts +0 -113
  372. package/src/_internal/util/vs/platform/instantiation/common/instantiation.ts +0 -127
  373. package/src/_internal/util/vs/platform/instantiation/common/instantiationService.ts +0 -483
  374. package/src/_internal/util/vs/platform/instantiation/common/serviceCollection.ts +0 -34
  375. package/src/_internal/util/vs/vscode-globals-nls.d.ts +0 -42
  376. package/src/_internal/util/vs/vscode-globals-product.d.ts +0 -35
  377. package/src/_internal/util/vs/workbench/api/common/extHostTypes/diagnostic.ts +0 -109
  378. package/src/_internal/util/vs/workbench/api/common/extHostTypes/es5ClassCompat.ts +0 -34
  379. package/src/_internal/util/vs/workbench/api/common/extHostTypes/location.ts +0 -51
  380. package/src/_internal/util/vs/workbench/api/common/extHostTypes/markdownString.ts +0 -83
  381. package/src/_internal/util/vs/workbench/api/common/extHostTypes/notebooks.ts +0 -296
  382. package/src/_internal/util/vs/workbench/api/common/extHostTypes/position.ts +0 -195
  383. package/src/_internal/util/vs/workbench/api/common/extHostTypes/range.ts +0 -167
  384. package/src/_internal/util/vs/workbench/api/common/extHostTypes/selection.ts +0 -94
  385. package/src/_internal/util/vs/workbench/api/common/extHostTypes/snippetString.ts +0 -103
  386. package/src/_internal/util/vs/workbench/api/common/extHostTypes/snippetTextEdit.ts +0 -44
  387. package/src/_internal/util/vs/workbench/api/common/extHostTypes/symbolInformation.ts +0 -89
  388. package/src/_internal/util/vs/workbench/api/common/extHostTypes/textEdit.ts +0 -99
  389. package/src/_internal/vscodeTypes.ts +0 -100
  390. package/src/main.ts +0 -207
  391. package/src/package.json +0 -4063
@@ -1,1591 +0,0 @@
1
- //!!! DO NOT modify, this file was COPIED from 'microsoft/vscode'
2
-
3
- /*---------------------------------------------------------------------------------------------
4
- * Copyright (c) Microsoft Corporation. All rights reserved.
5
- * Licensed under the MIT License. See License.txt in the project root for license information.
6
- *--------------------------------------------------------------------------------------------*/
7
-
8
- // NOTE: VSCode's copy of nodejs path library to be usable in common (non-node) namespace
9
- // Copied from: https://github.com/nodejs/node/commits/v22.15.0/lib/path.js
10
- // Excluding: the change that adds primordials
11
- // (https://github.com/nodejs/node/commit/187a862d221dec42fa9a5c4214e7034d9092792f and others)
12
- // Excluding: the change that adds glob matching
13
- // (https://github.com/nodejs/node/commit/57b8b8e18e5e2007114c63b71bf0baedc01936a6)
14
-
15
- /**
16
- * Copyright Joyent, Inc. and other Node contributors.
17
- *
18
- * Permission is hereby granted, free of charge, to any person obtaining a
19
- * copy of this software and associated documentation files (the
20
- * "Software"), to deal in the Software without restriction, including
21
- * without limitation the rights to use, copy, modify, merge, publish,
22
- * distribute, sublicense, and/or sell copies of the Software, and to permit
23
- * persons to whom the Software is furnished to do so, subject to the
24
- * following conditions:
25
- *
26
- * The above copyright notice and this permission notice shall be included
27
- * in all copies or substantial portions of the Software.
28
- *
29
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
30
- * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
31
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
32
- * NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
33
- * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
34
- * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
35
- * USE OR OTHER DEALINGS IN THE SOFTWARE.
36
- */
37
-
38
- import * as process from './process';
39
-
40
- const CHAR_UPPERCASE_A = 65;/* A */
41
- const CHAR_LOWERCASE_A = 97; /* a */
42
- const CHAR_UPPERCASE_Z = 90; /* Z */
43
- const CHAR_LOWERCASE_Z = 122; /* z */
44
- const CHAR_DOT = 46; /* . */
45
- const CHAR_FORWARD_SLASH = 47; /* / */
46
- const CHAR_BACKWARD_SLASH = 92; /* \ */
47
- const CHAR_COLON = 58; /* : */
48
- const CHAR_QUESTION_MARK = 63; /* ? */
49
-
50
- class ErrorInvalidArgType extends Error {
51
- code: 'ERR_INVALID_ARG_TYPE';
52
- constructor(name: string, expected: string, actual: unknown) {
53
- // determiner: 'must be' or 'must not be'
54
- let determiner;
55
- if (typeof expected === 'string' && expected.indexOf('not ') === 0) {
56
- determiner = 'must not be';
57
- expected = expected.replace(/^not /, '');
58
- } else {
59
- determiner = 'must be';
60
- }
61
-
62
- const type = name.indexOf('.') !== -1 ? 'property' : 'argument';
63
- let msg = `The "${name}" ${type} ${determiner} of type ${expected}`;
64
-
65
- msg += `. Received type ${typeof actual}`;
66
- super(msg);
67
-
68
- this.code = 'ERR_INVALID_ARG_TYPE';
69
- }
70
- }
71
-
72
- function validateObject(pathObject: object, name: string) {
73
- if (pathObject === null || typeof pathObject !== 'object') {
74
- throw new ErrorInvalidArgType(name, 'Object', pathObject);
75
- }
76
- }
77
-
78
- function validateString(value: string, name: string) {
79
- if (typeof value !== 'string') {
80
- throw new ErrorInvalidArgType(name, 'string', value);
81
- }
82
- }
83
-
84
- const platformIsWin32 = (process.platform === 'win32');
85
-
86
- function isPathSeparator(code: number | undefined) {
87
- return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
88
- }
89
-
90
- function isPosixPathSeparator(code: number | undefined) {
91
- return code === CHAR_FORWARD_SLASH;
92
- }
93
-
94
- function isWindowsDeviceRoot(code: number) {
95
- return (code >= CHAR_UPPERCASE_A && code <= CHAR_UPPERCASE_Z) ||
96
- (code >= CHAR_LOWERCASE_A && code <= CHAR_LOWERCASE_Z);
97
- }
98
-
99
- // Resolves . and .. elements in a path with directory names
100
- function normalizeString(path: string, allowAboveRoot: boolean, separator: string, isPathSeparator: (code?: number) => boolean) {
101
- let res = '';
102
- let lastSegmentLength = 0;
103
- let lastSlash = -1;
104
- let dots = 0;
105
- let code = 0;
106
- for (let i = 0; i <= path.length; ++i) {
107
- if (i < path.length) {
108
- code = path.charCodeAt(i);
109
- }
110
- else if (isPathSeparator(code)) {
111
- break;
112
- }
113
- else {
114
- code = CHAR_FORWARD_SLASH;
115
- }
116
-
117
- if (isPathSeparator(code)) {
118
- if (lastSlash === i - 1 || dots === 1) {
119
- // NOOP
120
- } else if (dots === 2) {
121
- if (res.length < 2 || lastSegmentLength !== 2 ||
122
- res.charCodeAt(res.length - 1) !== CHAR_DOT ||
123
- res.charCodeAt(res.length - 2) !== CHAR_DOT) {
124
- if (res.length > 2) {
125
- const lastSlashIndex = res.lastIndexOf(separator);
126
- if (lastSlashIndex === -1) {
127
- res = '';
128
- lastSegmentLength = 0;
129
- } else {
130
- res = res.slice(0, lastSlashIndex);
131
- lastSegmentLength = res.length - 1 - res.lastIndexOf(separator);
132
- }
133
- lastSlash = i;
134
- dots = 0;
135
- continue;
136
- } else if (res.length !== 0) {
137
- res = '';
138
- lastSegmentLength = 0;
139
- lastSlash = i;
140
- dots = 0;
141
- continue;
142
- }
143
- }
144
- if (allowAboveRoot) {
145
- res += res.length > 0 ? `${separator}..` : '..';
146
- lastSegmentLength = 2;
147
- }
148
- } else {
149
- if (res.length > 0) {
150
- res += `${separator}${path.slice(lastSlash + 1, i)}`;
151
- }
152
- else {
153
- res = path.slice(lastSlash + 1, i);
154
- }
155
- lastSegmentLength = i - lastSlash - 1;
156
- }
157
- lastSlash = i;
158
- dots = 0;
159
- } else if (code === CHAR_DOT && dots !== -1) {
160
- ++dots;
161
- } else {
162
- dots = -1;
163
- }
164
- }
165
- return res;
166
- }
167
-
168
- function formatExt(ext: string): string {
169
- return ext ? `${ext[0] === '.' ? '' : '.'}${ext}` : '';
170
- }
171
-
172
- function _format(sep: string, pathObject: ParsedPath) {
173
- validateObject(pathObject, 'pathObject');
174
- const dir = pathObject.dir || pathObject.root;
175
- const base = pathObject.base ||
176
- `${pathObject.name || ''}${formatExt(pathObject.ext)}`;
177
- if (!dir) {
178
- return base;
179
- }
180
- return dir === pathObject.root ? `${dir}${base}` : `${dir}${sep}${base}`;
181
- }
182
-
183
- export interface ParsedPath {
184
- root: string;
185
- dir: string;
186
- base: string;
187
- ext: string;
188
- name: string;
189
- }
190
-
191
- export interface IPath {
192
- normalize(path: string): string;
193
- isAbsolute(path: string): boolean;
194
- join(...paths: string[]): string;
195
- resolve(...pathSegments: string[]): string;
196
- relative(from: string, to: string): string;
197
- dirname(path: string): string;
198
- basename(path: string, suffix?: string): string;
199
- extname(path: string): string;
200
- format(pathObject: ParsedPath): string;
201
- parse(path: string): ParsedPath;
202
- toNamespacedPath(path: string): string;
203
- sep: '\\' | '/';
204
- delimiter: string;
205
- win32: IPath | null;
206
- posix: IPath | null;
207
- }
208
-
209
- export const win32: IPath = {
210
- // path.resolve([from ...], to)
211
- resolve(...pathSegments: string[]): string {
212
- let resolvedDevice = '';
213
- let resolvedTail = '';
214
- let resolvedAbsolute = false;
215
-
216
- for (let i = pathSegments.length - 1; i >= -1; i--) {
217
- let path;
218
- if (i >= 0) {
219
- path = pathSegments[i];
220
- validateString(path, `paths[${i}]`);
221
-
222
- // Skip empty entries
223
- if (path.length === 0) {
224
- continue;
225
- }
226
- } else if (resolvedDevice.length === 0) {
227
- path = process.cwd();
228
- } else {
229
- // Windows has the concept of drive-specific current working
230
- // directories. If we've resolved a drive letter but not yet an
231
- // absolute path, get cwd for that drive, or the process cwd if
232
- // the drive cwd is not available. We're sure the device is not
233
- // a UNC path at this points, because UNC paths are always absolute.
234
- path = process.env[`=${resolvedDevice}`] || process.cwd();
235
-
236
- // Verify that a cwd was found and that it actually points
237
- // to our drive. If not, default to the drive's root.
238
- if (path === undefined ||
239
- (path.slice(0, 2).toLowerCase() !== resolvedDevice.toLowerCase() &&
240
- path.charCodeAt(2) === CHAR_BACKWARD_SLASH)) {
241
- path = `${resolvedDevice}\\`;
242
- }
243
- }
244
-
245
- const len = path.length;
246
- let rootEnd = 0;
247
- let device = '';
248
- let isAbsolute = false;
249
- const code = path.charCodeAt(0);
250
-
251
- // Try to match a root
252
- if (len === 1) {
253
- if (isPathSeparator(code)) {
254
- // `path` contains just a path separator
255
- rootEnd = 1;
256
- isAbsolute = true;
257
- }
258
- } else if (isPathSeparator(code)) {
259
- // Possible UNC root
260
-
261
- // If we started with a separator, we know we at least have an
262
- // absolute path of some kind (UNC or otherwise)
263
- isAbsolute = true;
264
-
265
- if (isPathSeparator(path.charCodeAt(1))) {
266
- // Matched double path separator at beginning
267
- let j = 2;
268
- let last = j;
269
- // Match 1 or more non-path separators
270
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
271
- j++;
272
- }
273
- if (j < len && j !== last) {
274
- const firstPart = path.slice(last, j);
275
- // Matched!
276
- last = j;
277
- // Match 1 or more path separators
278
- while (j < len && isPathSeparator(path.charCodeAt(j))) {
279
- j++;
280
- }
281
- if (j < len && j !== last) {
282
- // Matched!
283
- last = j;
284
- // Match 1 or more non-path separators
285
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
286
- j++;
287
- }
288
- if (j === len || j !== last) {
289
- // We matched a UNC root
290
- device = `\\\\${firstPart}\\${path.slice(last, j)}`;
291
- rootEnd = j;
292
- }
293
- }
294
- }
295
- } else {
296
- rootEnd = 1;
297
- }
298
- } else if (isWindowsDeviceRoot(code) &&
299
- path.charCodeAt(1) === CHAR_COLON) {
300
- // Possible device root
301
- device = path.slice(0, 2);
302
- rootEnd = 2;
303
- if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
304
- // Treat separator following drive name as an absolute path
305
- // indicator
306
- isAbsolute = true;
307
- rootEnd = 3;
308
- }
309
- }
310
-
311
- if (device.length > 0) {
312
- if (resolvedDevice.length > 0) {
313
- if (device.toLowerCase() !== resolvedDevice.toLowerCase()) {
314
- // This path points to another device so it is not applicable
315
- continue;
316
- }
317
- } else {
318
- resolvedDevice = device;
319
- }
320
- }
321
-
322
- if (resolvedAbsolute) {
323
- if (resolvedDevice.length > 0) {
324
- break;
325
- }
326
- } else {
327
- resolvedTail = `${path.slice(rootEnd)}\\${resolvedTail}`;
328
- resolvedAbsolute = isAbsolute;
329
- if (isAbsolute && resolvedDevice.length > 0) {
330
- break;
331
- }
332
- }
333
- }
334
-
335
- // At this point the path should be resolved to a full absolute path,
336
- // but handle relative paths to be safe (might happen when process.cwd()
337
- // fails)
338
-
339
- // Normalize the tail path
340
- resolvedTail = normalizeString(resolvedTail, !resolvedAbsolute, '\\',
341
- isPathSeparator);
342
-
343
- return resolvedAbsolute ?
344
- `${resolvedDevice}\\${resolvedTail}` :
345
- `${resolvedDevice}${resolvedTail}` || '.';
346
- },
347
-
348
- normalize(path: string): string {
349
- validateString(path, 'path');
350
- const len = path.length;
351
- if (len === 0) {
352
- return '.';
353
- }
354
- let rootEnd = 0;
355
- let device;
356
- let isAbsolute = false;
357
- const code = path.charCodeAt(0);
358
-
359
- // Try to match a root
360
- if (len === 1) {
361
- // `path` contains just a single char, exit early to avoid
362
- // unnecessary work
363
- return isPosixPathSeparator(code) ? '\\' : path;
364
- }
365
- if (isPathSeparator(code)) {
366
- // Possible UNC root
367
-
368
- // If we started with a separator, we know we at least have an absolute
369
- // path of some kind (UNC or otherwise)
370
- isAbsolute = true;
371
-
372
- if (isPathSeparator(path.charCodeAt(1))) {
373
- // Matched double path separator at beginning
374
- let j = 2;
375
- let last = j;
376
- // Match 1 or more non-path separators
377
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
378
- j++;
379
- }
380
- if (j < len && j !== last) {
381
- const firstPart = path.slice(last, j);
382
- // Matched!
383
- last = j;
384
- // Match 1 or more path separators
385
- while (j < len && isPathSeparator(path.charCodeAt(j))) {
386
- j++;
387
- }
388
- if (j < len && j !== last) {
389
- // Matched!
390
- last = j;
391
- // Match 1 or more non-path separators
392
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
393
- j++;
394
- }
395
- if (j === len) {
396
- // We matched a UNC root only
397
- // Return the normalized version of the UNC root since there
398
- // is nothing left to process
399
- return `\\\\${firstPart}\\${path.slice(last)}\\`;
400
- }
401
- if (j !== last) {
402
- // We matched a UNC root with leftovers
403
- device = `\\\\${firstPart}\\${path.slice(last, j)}`;
404
- rootEnd = j;
405
- }
406
- }
407
- }
408
- } else {
409
- rootEnd = 1;
410
- }
411
- } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
412
- // Possible device root
413
- device = path.slice(0, 2);
414
- rootEnd = 2;
415
- if (len > 2 && isPathSeparator(path.charCodeAt(2))) {
416
- // Treat separator following drive name as an absolute path
417
- // indicator
418
- isAbsolute = true;
419
- rootEnd = 3;
420
- }
421
- }
422
-
423
- let tail = rootEnd < len ?
424
- normalizeString(path.slice(rootEnd), !isAbsolute, '\\', isPathSeparator) :
425
- '';
426
- if (tail.length === 0 && !isAbsolute) {
427
- tail = '.';
428
- }
429
- if (tail.length > 0 && isPathSeparator(path.charCodeAt(len - 1))) {
430
- tail += '\\';
431
- }
432
- if (!isAbsolute && device === undefined && path.includes(':')) {
433
- // If the original path was not absolute and if we have not been able to
434
- // resolve it relative to a particular device, we need to ensure that the
435
- // `tail` has not become something that Windows might interpret as an
436
- // absolute path. See CVE-2024-36139.
437
- if (tail.length >= 2 &&
438
- isWindowsDeviceRoot(tail.charCodeAt(0)) &&
439
- tail.charCodeAt(1) === CHAR_COLON) {
440
- return `.\\${tail}`;
441
- }
442
- let index = path.indexOf(':');
443
- do {
444
- if (index === len - 1 || isPathSeparator(path.charCodeAt(index + 1))) {
445
- return `.\\${tail}`;
446
- }
447
- } while ((index = path.indexOf(':', index + 1)) !== -1);
448
- }
449
- if (device === undefined) {
450
- return isAbsolute ? `\\${tail}` : tail;
451
- }
452
- return isAbsolute ? `${device}\\${tail}` : `${device}${tail}`;
453
- },
454
-
455
- isAbsolute(path: string): boolean {
456
- validateString(path, 'path');
457
- const len = path.length;
458
- if (len === 0) {
459
- return false;
460
- }
461
-
462
- const code = path.charCodeAt(0);
463
- return isPathSeparator(code) ||
464
- // Possible device root
465
- (len > 2 &&
466
- isWindowsDeviceRoot(code) &&
467
- path.charCodeAt(1) === CHAR_COLON &&
468
- isPathSeparator(path.charCodeAt(2)));
469
- },
470
-
471
- join(...paths: string[]): string {
472
- if (paths.length === 0) {
473
- return '.';
474
- }
475
-
476
- let joined;
477
- let firstPart: string | undefined;
478
- for (let i = 0; i < paths.length; ++i) {
479
- const arg = paths[i];
480
- validateString(arg, 'path');
481
- if (arg.length > 0) {
482
- if (joined === undefined) {
483
- joined = firstPart = arg;
484
- }
485
- else {
486
- joined += `\\${arg}`;
487
- }
488
- }
489
- }
490
-
491
- if (joined === undefined) {
492
- return '.';
493
- }
494
-
495
- // Make sure that the joined path doesn't start with two slashes, because
496
- // normalize() will mistake it for a UNC path then.
497
- //
498
- // This step is skipped when it is very clear that the user actually
499
- // intended to point at a UNC path. This is assumed when the first
500
- // non-empty string arguments starts with exactly two slashes followed by
501
- // at least one more non-slash character.
502
- //
503
- // Note that for normalize() to treat a path as a UNC path it needs to
504
- // have at least 2 components, so we don't filter for that here.
505
- // This means that the user can use join to construct UNC paths from
506
- // a server name and a share name; for example:
507
- // path.join('//server', 'share') -> '\\\\server\\share\\')
508
- let needsReplace = true;
509
- let slashCount = 0;
510
- if (typeof firstPart === 'string' && isPathSeparator(firstPart.charCodeAt(0))) {
511
- ++slashCount;
512
- const firstLen = firstPart.length;
513
- if (firstLen > 1 && isPathSeparator(firstPart.charCodeAt(1))) {
514
- ++slashCount;
515
- if (firstLen > 2) {
516
- if (isPathSeparator(firstPart.charCodeAt(2))) {
517
- ++slashCount;
518
- } else {
519
- // We matched a UNC path in the first part
520
- needsReplace = false;
521
- }
522
- }
523
- }
524
- }
525
- if (needsReplace) {
526
- // Find any more consecutive slashes we need to replace
527
- while (slashCount < joined.length &&
528
- isPathSeparator(joined.charCodeAt(slashCount))) {
529
- slashCount++;
530
- }
531
-
532
- // Replace the slashes if needed
533
- if (slashCount >= 2) {
534
- joined = `\\${joined.slice(slashCount)}`;
535
- }
536
- }
537
-
538
- return win32.normalize(joined);
539
- },
540
-
541
-
542
- // It will solve the relative path from `from` to `to`, for instance:
543
- // from = 'C:\\orandea\\test\\aaa'
544
- // to = 'C:\\orandea\\impl\\bbb'
545
- // The output of the function should be: '..\\..\\impl\\bbb'
546
- relative(from: string, to: string): string {
547
- validateString(from, 'from');
548
- validateString(to, 'to');
549
-
550
- if (from === to) {
551
- return '';
552
- }
553
-
554
- const fromOrig = win32.resolve(from);
555
- const toOrig = win32.resolve(to);
556
-
557
- if (fromOrig === toOrig) {
558
- return '';
559
- }
560
-
561
- from = fromOrig.toLowerCase();
562
- to = toOrig.toLowerCase();
563
-
564
- if (from === to) {
565
- return '';
566
- }
567
-
568
- if (fromOrig.length !== from.length || toOrig.length !== to.length) {
569
- const fromSplit = fromOrig.split('\\');
570
- const toSplit = toOrig.split('\\');
571
- if (fromSplit[fromSplit.length - 1] === '') {
572
- fromSplit.pop();
573
- }
574
- if (toSplit[toSplit.length - 1] === '') {
575
- toSplit.pop();
576
- }
577
-
578
- const fromLen = fromSplit.length;
579
- const toLen = toSplit.length;
580
- const length = fromLen < toLen ? fromLen : toLen;
581
-
582
- let i;
583
- for (i = 0; i < length; i++) {
584
- if (fromSplit[i].toLowerCase() !== toSplit[i].toLowerCase()) {
585
- break;
586
- }
587
- }
588
-
589
- if (i === 0) {
590
- return toOrig;
591
- } else if (i === length) {
592
- if (toLen > length) {
593
- return toSplit.slice(i).join('\\');
594
- }
595
- if (fromLen > length) {
596
- return '..\\'.repeat(fromLen - 1 - i) + '..';
597
- }
598
- return '';
599
- }
600
-
601
- return '..\\'.repeat(fromLen - i) + toSplit.slice(i).join('\\');
602
- }
603
-
604
- // Trim any leading backslashes
605
- let fromStart = 0;
606
- while (fromStart < from.length &&
607
- from.charCodeAt(fromStart) === CHAR_BACKWARD_SLASH) {
608
- fromStart++;
609
- }
610
- // Trim trailing backslashes (applicable to UNC paths only)
611
- let fromEnd = from.length;
612
- while (fromEnd - 1 > fromStart &&
613
- from.charCodeAt(fromEnd - 1) === CHAR_BACKWARD_SLASH) {
614
- fromEnd--;
615
- }
616
- const fromLen = fromEnd - fromStart;
617
-
618
- // Trim any leading backslashes
619
- let toStart = 0;
620
- while (toStart < to.length &&
621
- to.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) {
622
- toStart++;
623
- }
624
- // Trim trailing backslashes (applicable to UNC paths only)
625
- let toEnd = to.length;
626
- while (toEnd - 1 > toStart &&
627
- to.charCodeAt(toEnd - 1) === CHAR_BACKWARD_SLASH) {
628
- toEnd--;
629
- }
630
- const toLen = toEnd - toStart;
631
-
632
- // Compare paths to find the longest common path from root
633
- const length = fromLen < toLen ? fromLen : toLen;
634
- let lastCommonSep = -1;
635
- let i = 0;
636
- for (; i < length; i++) {
637
- const fromCode = from.charCodeAt(fromStart + i);
638
- if (fromCode !== to.charCodeAt(toStart + i)) {
639
- break;
640
- } else if (fromCode === CHAR_BACKWARD_SLASH) {
641
- lastCommonSep = i;
642
- }
643
- }
644
-
645
- // We found a mismatch before the first common path separator was seen, so
646
- // return the original `to`.
647
- if (i !== length) {
648
- if (lastCommonSep === -1) {
649
- return toOrig;
650
- }
651
- } else {
652
- if (toLen > length) {
653
- if (to.charCodeAt(toStart + i) === CHAR_BACKWARD_SLASH) {
654
- // We get here if `from` is the exact base path for `to`.
655
- // For example: from='C:\\foo\\bar'; to='C:\\foo\\bar\\baz'
656
- return toOrig.slice(toStart + i + 1);
657
- }
658
- if (i === 2) {
659
- // We get here if `from` is the device root.
660
- // For example: from='C:\\'; to='C:\\foo'
661
- return toOrig.slice(toStart + i);
662
- }
663
- }
664
- if (fromLen > length) {
665
- if (from.charCodeAt(fromStart + i) === CHAR_BACKWARD_SLASH) {
666
- // We get here if `to` is the exact base path for `from`.
667
- // For example: from='C:\\foo\\bar'; to='C:\\foo'
668
- lastCommonSep = i;
669
- } else if (i === 2) {
670
- // We get here if `to` is the device root.
671
- // For example: from='C:\\foo\\bar'; to='C:\\'
672
- lastCommonSep = 3;
673
- }
674
- }
675
- if (lastCommonSep === -1) {
676
- lastCommonSep = 0;
677
- }
678
- }
679
-
680
- let out = '';
681
- // Generate the relative path based on the path difference between `to` and
682
- // `from`
683
- for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
684
- if (i === fromEnd || from.charCodeAt(i) === CHAR_BACKWARD_SLASH) {
685
- out += out.length === 0 ? '..' : '\\..';
686
- }
687
- }
688
-
689
- toStart += lastCommonSep;
690
-
691
- // Lastly, append the rest of the destination (`to`) path that comes after
692
- // the common path parts
693
- if (out.length > 0) {
694
- return `${out}${toOrig.slice(toStart, toEnd)}`;
695
- }
696
-
697
- if (toOrig.charCodeAt(toStart) === CHAR_BACKWARD_SLASH) {
698
- ++toStart;
699
- }
700
-
701
- return toOrig.slice(toStart, toEnd);
702
- },
703
-
704
- toNamespacedPath(path: string): string {
705
- // Note: this will *probably* throw somewhere.
706
- if (typeof path !== 'string' || path.length === 0) {
707
- return path;
708
- }
709
-
710
- const resolvedPath = win32.resolve(path);
711
-
712
- if (resolvedPath.length <= 2) {
713
- return path;
714
- }
715
-
716
- if (resolvedPath.charCodeAt(0) === CHAR_BACKWARD_SLASH) {
717
- // Possible UNC root
718
- if (resolvedPath.charCodeAt(1) === CHAR_BACKWARD_SLASH) {
719
- const code = resolvedPath.charCodeAt(2);
720
- if (code !== CHAR_QUESTION_MARK && code !== CHAR_DOT) {
721
- // Matched non-long UNC root, convert the path to a long UNC path
722
- return `\\\\?\\UNC\\${resolvedPath.slice(2)}`;
723
- }
724
- }
725
- } else if (isWindowsDeviceRoot(resolvedPath.charCodeAt(0)) &&
726
- resolvedPath.charCodeAt(1) === CHAR_COLON &&
727
- resolvedPath.charCodeAt(2) === CHAR_BACKWARD_SLASH) {
728
- // Matched device root, convert the path to a long UNC path
729
- return `\\\\?\\${resolvedPath}`;
730
- }
731
-
732
- return resolvedPath;
733
- },
734
-
735
- dirname(path: string): string {
736
- validateString(path, 'path');
737
- const len = path.length;
738
- if (len === 0) {
739
- return '.';
740
- }
741
- let rootEnd = -1;
742
- let offset = 0;
743
- const code = path.charCodeAt(0);
744
-
745
- if (len === 1) {
746
- // `path` contains just a path separator, exit early to avoid
747
- // unnecessary work or a dot.
748
- return isPathSeparator(code) ? path : '.';
749
- }
750
-
751
- // Try to match a root
752
- if (isPathSeparator(code)) {
753
- // Possible UNC root
754
-
755
- rootEnd = offset = 1;
756
-
757
- if (isPathSeparator(path.charCodeAt(1))) {
758
- // Matched double path separator at beginning
759
- let j = 2;
760
- let last = j;
761
- // Match 1 or more non-path separators
762
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
763
- j++;
764
- }
765
- if (j < len && j !== last) {
766
- // Matched!
767
- last = j;
768
- // Match 1 or more path separators
769
- while (j < len && isPathSeparator(path.charCodeAt(j))) {
770
- j++;
771
- }
772
- if (j < len && j !== last) {
773
- // Matched!
774
- last = j;
775
- // Match 1 or more non-path separators
776
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
777
- j++;
778
- }
779
- if (j === len) {
780
- // We matched a UNC root only
781
- return path;
782
- }
783
- if (j !== last) {
784
- // We matched a UNC root with leftovers
785
-
786
- // Offset by 1 to include the separator after the UNC root to
787
- // treat it as a "normal root" on top of a (UNC) root
788
- rootEnd = offset = j + 1;
789
- }
790
- }
791
- }
792
- }
793
- // Possible device root
794
- } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
795
- rootEnd = len > 2 && isPathSeparator(path.charCodeAt(2)) ? 3 : 2;
796
- offset = rootEnd;
797
- }
798
-
799
- let end = -1;
800
- let matchedSlash = true;
801
- for (let i = len - 1; i >= offset; --i) {
802
- if (isPathSeparator(path.charCodeAt(i))) {
803
- if (!matchedSlash) {
804
- end = i;
805
- break;
806
- }
807
- } else {
808
- // We saw the first non-path separator
809
- matchedSlash = false;
810
- }
811
- }
812
-
813
- if (end === -1) {
814
- if (rootEnd === -1) {
815
- return '.';
816
- }
817
-
818
- end = rootEnd;
819
- }
820
- return path.slice(0, end);
821
- },
822
-
823
- basename(path: string, suffix?: string): string {
824
- if (suffix !== undefined) {
825
- validateString(suffix, 'suffix');
826
- }
827
- validateString(path, 'path');
828
- let start = 0;
829
- let end = -1;
830
- let matchedSlash = true;
831
- let i;
832
-
833
- // Check for a drive letter prefix so as not to mistake the following
834
- // path separator as an extra separator at the end of the path that can be
835
- // disregarded
836
- if (path.length >= 2 &&
837
- isWindowsDeviceRoot(path.charCodeAt(0)) &&
838
- path.charCodeAt(1) === CHAR_COLON) {
839
- start = 2;
840
- }
841
-
842
- if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
843
- if (suffix === path) {
844
- return '';
845
- }
846
- let extIdx = suffix.length - 1;
847
- let firstNonSlashEnd = -1;
848
- for (i = path.length - 1; i >= start; --i) {
849
- const code = path.charCodeAt(i);
850
- if (isPathSeparator(code)) {
851
- // If we reached a path separator that was not part of a set of path
852
- // separators at the end of the string, stop now
853
- if (!matchedSlash) {
854
- start = i + 1;
855
- break;
856
- }
857
- } else {
858
- if (firstNonSlashEnd === -1) {
859
- // We saw the first non-path separator, remember this index in case
860
- // we need it if the extension ends up not matching
861
- matchedSlash = false;
862
- firstNonSlashEnd = i + 1;
863
- }
864
- if (extIdx >= 0) {
865
- // Try to match the explicit extension
866
- if (code === suffix.charCodeAt(extIdx)) {
867
- if (--extIdx === -1) {
868
- // We matched the extension, so mark this as the end of our path
869
- // component
870
- end = i;
871
- }
872
- } else {
873
- // Extension does not match, so our result is the entire path
874
- // component
875
- extIdx = -1;
876
- end = firstNonSlashEnd;
877
- }
878
- }
879
- }
880
- }
881
-
882
- if (start === end) {
883
- end = firstNonSlashEnd;
884
- } else if (end === -1) {
885
- end = path.length;
886
- }
887
- return path.slice(start, end);
888
- }
889
- for (i = path.length - 1; i >= start; --i) {
890
- if (isPathSeparator(path.charCodeAt(i))) {
891
- // If we reached a path separator that was not part of a set of path
892
- // separators at the end of the string, stop now
893
- if (!matchedSlash) {
894
- start = i + 1;
895
- break;
896
- }
897
- } else if (end === -1) {
898
- // We saw the first non-path separator, mark this as the end of our
899
- // path component
900
- matchedSlash = false;
901
- end = i + 1;
902
- }
903
- }
904
-
905
- if (end === -1) {
906
- return '';
907
- }
908
- return path.slice(start, end);
909
- },
910
-
911
- extname(path: string): string {
912
- validateString(path, 'path');
913
- let start = 0;
914
- let startDot = -1;
915
- let startPart = 0;
916
- let end = -1;
917
- let matchedSlash = true;
918
- // Track the state of characters (if any) we see before our first dot and
919
- // after any path separator we find
920
- let preDotState = 0;
921
-
922
- // Check for a drive letter prefix so as not to mistake the following
923
- // path separator as an extra separator at the end of the path that can be
924
- // disregarded
925
-
926
- if (path.length >= 2 &&
927
- path.charCodeAt(1) === CHAR_COLON &&
928
- isWindowsDeviceRoot(path.charCodeAt(0))) {
929
- start = startPart = 2;
930
- }
931
-
932
- for (let i = path.length - 1; i >= start; --i) {
933
- const code = path.charCodeAt(i);
934
- if (isPathSeparator(code)) {
935
- // If we reached a path separator that was not part of a set of path
936
- // separators at the end of the string, stop now
937
- if (!matchedSlash) {
938
- startPart = i + 1;
939
- break;
940
- }
941
- continue;
942
- }
943
- if (end === -1) {
944
- // We saw the first non-path separator, mark this as the end of our
945
- // extension
946
- matchedSlash = false;
947
- end = i + 1;
948
- }
949
- if (code === CHAR_DOT) {
950
- // If this is our first dot, mark it as the start of our extension
951
- if (startDot === -1) {
952
- startDot = i;
953
- }
954
- else if (preDotState !== 1) {
955
- preDotState = 1;
956
- }
957
- } else if (startDot !== -1) {
958
- // We saw a non-dot and non-path separator before our dot, so we should
959
- // have a good chance at having a non-empty extension
960
- preDotState = -1;
961
- }
962
- }
963
-
964
- if (startDot === -1 ||
965
- end === -1 ||
966
- // We saw a non-dot character immediately before the dot
967
- preDotState === 0 ||
968
- // The (right-most) trimmed path component is exactly '..'
969
- (preDotState === 1 &&
970
- startDot === end - 1 &&
971
- startDot === startPart + 1)) {
972
- return '';
973
- }
974
- return path.slice(startDot, end);
975
- },
976
-
977
- format: _format.bind(null, '\\'),
978
-
979
- parse(path) {
980
- validateString(path, 'path');
981
-
982
- const ret = { root: '', dir: '', base: '', ext: '', name: '' };
983
- if (path.length === 0) {
984
- return ret;
985
- }
986
-
987
- const len = path.length;
988
- let rootEnd = 0;
989
- let code = path.charCodeAt(0);
990
-
991
- if (len === 1) {
992
- if (isPathSeparator(code)) {
993
- // `path` contains just a path separator, exit early to avoid
994
- // unnecessary work
995
- ret.root = ret.dir = path;
996
- return ret;
997
- }
998
- ret.base = ret.name = path;
999
- return ret;
1000
- }
1001
- // Try to match a root
1002
- if (isPathSeparator(code)) {
1003
- // Possible UNC root
1004
-
1005
- rootEnd = 1;
1006
- if (isPathSeparator(path.charCodeAt(1))) {
1007
- // Matched double path separator at beginning
1008
- let j = 2;
1009
- let last = j;
1010
- // Match 1 or more non-path separators
1011
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
1012
- j++;
1013
- }
1014
- if (j < len && j !== last) {
1015
- // Matched!
1016
- last = j;
1017
- // Match 1 or more path separators
1018
- while (j < len && isPathSeparator(path.charCodeAt(j))) {
1019
- j++;
1020
- }
1021
- if (j < len && j !== last) {
1022
- // Matched!
1023
- last = j;
1024
- // Match 1 or more non-path separators
1025
- while (j < len && !isPathSeparator(path.charCodeAt(j))) {
1026
- j++;
1027
- }
1028
- if (j === len) {
1029
- // We matched a UNC root only
1030
- rootEnd = j;
1031
- } else if (j !== last) {
1032
- // We matched a UNC root with leftovers
1033
- rootEnd = j + 1;
1034
- }
1035
- }
1036
- }
1037
- }
1038
- } else if (isWindowsDeviceRoot(code) && path.charCodeAt(1) === CHAR_COLON) {
1039
- // Possible device root
1040
- if (len <= 2) {
1041
- // `path` contains just a drive root, exit early to avoid
1042
- // unnecessary work
1043
- ret.root = ret.dir = path;
1044
- return ret;
1045
- }
1046
- rootEnd = 2;
1047
- if (isPathSeparator(path.charCodeAt(2))) {
1048
- if (len === 3) {
1049
- // `path` contains just a drive root, exit early to avoid
1050
- // unnecessary work
1051
- ret.root = ret.dir = path;
1052
- return ret;
1053
- }
1054
- rootEnd = 3;
1055
- }
1056
- }
1057
- if (rootEnd > 0) {
1058
- ret.root = path.slice(0, rootEnd);
1059
- }
1060
-
1061
- let startDot = -1;
1062
- let startPart = rootEnd;
1063
- let end = -1;
1064
- let matchedSlash = true;
1065
- let i = path.length - 1;
1066
-
1067
- // Track the state of characters (if any) we see before our first dot and
1068
- // after any path separator we find
1069
- let preDotState = 0;
1070
-
1071
- // Get non-dir info
1072
- for (; i >= rootEnd; --i) {
1073
- code = path.charCodeAt(i);
1074
- if (isPathSeparator(code)) {
1075
- // If we reached a path separator that was not part of a set of path
1076
- // separators at the end of the string, stop now
1077
- if (!matchedSlash) {
1078
- startPart = i + 1;
1079
- break;
1080
- }
1081
- continue;
1082
- }
1083
- if (end === -1) {
1084
- // We saw the first non-path separator, mark this as the end of our
1085
- // extension
1086
- matchedSlash = false;
1087
- end = i + 1;
1088
- }
1089
- if (code === CHAR_DOT) {
1090
- // If this is our first dot, mark it as the start of our extension
1091
- if (startDot === -1) {
1092
- startDot = i;
1093
- } else if (preDotState !== 1) {
1094
- preDotState = 1;
1095
- }
1096
- } else if (startDot !== -1) {
1097
- // We saw a non-dot and non-path separator before our dot, so we should
1098
- // have a good chance at having a non-empty extension
1099
- preDotState = -1;
1100
- }
1101
- }
1102
-
1103
- if (end !== -1) {
1104
- if (startDot === -1 ||
1105
- // We saw a non-dot character immediately before the dot
1106
- preDotState === 0 ||
1107
- // The (right-most) trimmed path component is exactly '..'
1108
- (preDotState === 1 &&
1109
- startDot === end - 1 &&
1110
- startDot === startPart + 1)) {
1111
- ret.base = ret.name = path.slice(startPart, end);
1112
- } else {
1113
- ret.name = path.slice(startPart, startDot);
1114
- ret.base = path.slice(startPart, end);
1115
- ret.ext = path.slice(startDot, end);
1116
- }
1117
- }
1118
-
1119
- // If the directory is the root, use the entire root as the `dir` including
1120
- // the trailing slash if any (`C:\abc` -> `C:\`). Otherwise, strip out the
1121
- // trailing slash (`C:\abc\def` -> `C:\abc`).
1122
- if (startPart > 0 && startPart !== rootEnd) {
1123
- ret.dir = path.slice(0, startPart - 1);
1124
- } else {
1125
- ret.dir = ret.root;
1126
- }
1127
-
1128
- return ret;
1129
- },
1130
-
1131
- sep: '\\',
1132
- delimiter: ';',
1133
- win32: null,
1134
- posix: null
1135
- };
1136
-
1137
- const posixCwd = (() => {
1138
- if (platformIsWin32) {
1139
- // Converts Windows' backslash path separators to POSIX forward slashes
1140
- // and truncates any drive indicator
1141
- const regexp = /\\/g;
1142
- return () => {
1143
- const cwd = process.cwd().replace(regexp, '/');
1144
- return cwd.slice(cwd.indexOf('/'));
1145
- };
1146
- }
1147
-
1148
- // We're already on POSIX, no need for any transformations
1149
- return () => process.cwd();
1150
- })();
1151
-
1152
- export const posix: IPath = {
1153
- // path.resolve([from ...], to)
1154
- resolve(...pathSegments: string[]): string {
1155
- let resolvedPath = '';
1156
- let resolvedAbsolute = false;
1157
-
1158
- for (let i = pathSegments.length - 1; i >= 0 && !resolvedAbsolute; i--) {
1159
- const path = pathSegments[i];
1160
- validateString(path, `paths[${i}]`);
1161
-
1162
- // Skip empty entries
1163
- if (path.length === 0) {
1164
- continue;
1165
- }
1166
-
1167
- resolvedPath = `${path}/${resolvedPath}`;
1168
- resolvedAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1169
- }
1170
-
1171
- if (!resolvedAbsolute) {
1172
- const cwd = posixCwd();
1173
- resolvedPath = `${cwd}/${resolvedPath}`;
1174
- resolvedAbsolute =
1175
- cwd.charCodeAt(0) === CHAR_FORWARD_SLASH;
1176
- }
1177
-
1178
- // At this point the path should be resolved to a full absolute path, but
1179
- // handle relative paths to be safe (might happen when process.cwd() fails)
1180
-
1181
- // Normalize the path
1182
- resolvedPath = normalizeString(resolvedPath, !resolvedAbsolute, '/',
1183
- isPosixPathSeparator);
1184
-
1185
- if (resolvedAbsolute) {
1186
- return `/${resolvedPath}`;
1187
- }
1188
- return resolvedPath.length > 0 ? resolvedPath : '.';
1189
- },
1190
-
1191
- normalize(path: string): string {
1192
- validateString(path, 'path');
1193
-
1194
- if (path.length === 0) {
1195
- return '.';
1196
- }
1197
-
1198
- const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1199
- const trailingSeparator =
1200
- path.charCodeAt(path.length - 1) === CHAR_FORWARD_SLASH;
1201
-
1202
- // Normalize the path
1203
- path = normalizeString(path, !isAbsolute, '/', isPosixPathSeparator);
1204
-
1205
- if (path.length === 0) {
1206
- if (isAbsolute) {
1207
- return '/';
1208
- }
1209
- return trailingSeparator ? './' : '.';
1210
- }
1211
- if (trailingSeparator) {
1212
- path += '/';
1213
- }
1214
-
1215
- return isAbsolute ? `/${path}` : path;
1216
- },
1217
-
1218
- isAbsolute(path: string): boolean {
1219
- validateString(path, 'path');
1220
- return path.length > 0 && path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1221
- },
1222
-
1223
- join(...paths: string[]): string {
1224
- if (paths.length === 0) {
1225
- return '.';
1226
- }
1227
-
1228
- const path = [];
1229
- for (let i = 0; i < paths.length; ++i) {
1230
- const arg = paths[i];
1231
- validateString(arg, 'path');
1232
- if (arg.length > 0) {
1233
- path.push(arg);
1234
- }
1235
- }
1236
-
1237
- if (path.length === 0) {
1238
- return '.';
1239
- }
1240
-
1241
- return posix.normalize(path.join('/'));
1242
- },
1243
-
1244
- relative(from: string, to: string): string {
1245
- validateString(from, 'from');
1246
- validateString(to, 'to');
1247
-
1248
- if (from === to) {
1249
- return '';
1250
- }
1251
-
1252
- // Trim leading forward slashes.
1253
- from = posix.resolve(from);
1254
- to = posix.resolve(to);
1255
-
1256
- if (from === to) {
1257
- return '';
1258
- }
1259
-
1260
- const fromStart = 1;
1261
- const fromEnd = from.length;
1262
- const fromLen = fromEnd - fromStart;
1263
- const toStart = 1;
1264
- const toLen = to.length - toStart;
1265
-
1266
- // Compare paths to find the longest common path from root
1267
- const length = (fromLen < toLen ? fromLen : toLen);
1268
- let lastCommonSep = -1;
1269
- let i = 0;
1270
- for (; i < length; i++) {
1271
- const fromCode = from.charCodeAt(fromStart + i);
1272
- if (fromCode !== to.charCodeAt(toStart + i)) {
1273
- break;
1274
- } else if (fromCode === CHAR_FORWARD_SLASH) {
1275
- lastCommonSep = i;
1276
- }
1277
- }
1278
- if (i === length) {
1279
- if (toLen > length) {
1280
- if (to.charCodeAt(toStart + i) === CHAR_FORWARD_SLASH) {
1281
- // We get here if `from` is the exact base path for `to`.
1282
- // For example: from='/foo/bar'; to='/foo/bar/baz'
1283
- return to.slice(toStart + i + 1);
1284
- }
1285
- if (i === 0) {
1286
- // We get here if `from` is the root
1287
- // For example: from='/'; to='/foo'
1288
- return to.slice(toStart + i);
1289
- }
1290
- } else if (fromLen > length) {
1291
- if (from.charCodeAt(fromStart + i) === CHAR_FORWARD_SLASH) {
1292
- // We get here if `to` is the exact base path for `from`.
1293
- // For example: from='/foo/bar/baz'; to='/foo/bar'
1294
- lastCommonSep = i;
1295
- } else if (i === 0) {
1296
- // We get here if `to` is the root.
1297
- // For example: from='/foo/bar'; to='/'
1298
- lastCommonSep = 0;
1299
- }
1300
- }
1301
- }
1302
-
1303
- let out = '';
1304
- // Generate the relative path based on the path difference between `to`
1305
- // and `from`.
1306
- for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) {
1307
- if (i === fromEnd || from.charCodeAt(i) === CHAR_FORWARD_SLASH) {
1308
- out += out.length === 0 ? '..' : '/..';
1309
- }
1310
- }
1311
-
1312
- // Lastly, append the rest of the destination (`to`) path that comes after
1313
- // the common path parts.
1314
- return `${out}${to.slice(toStart + lastCommonSep)}`;
1315
- },
1316
-
1317
- toNamespacedPath(path: string): string {
1318
- // Non-op on posix systems
1319
- return path;
1320
- },
1321
-
1322
- dirname(path: string): string {
1323
- validateString(path, 'path');
1324
- if (path.length === 0) {
1325
- return '.';
1326
- }
1327
- const hasRoot = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1328
- let end = -1;
1329
- let matchedSlash = true;
1330
- for (let i = path.length - 1; i >= 1; --i) {
1331
- if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
1332
- if (!matchedSlash) {
1333
- end = i;
1334
- break;
1335
- }
1336
- } else {
1337
- // We saw the first non-path separator
1338
- matchedSlash = false;
1339
- }
1340
- }
1341
-
1342
- if (end === -1) {
1343
- return hasRoot ? '/' : '.';
1344
- }
1345
- if (hasRoot && end === 1) {
1346
- return '//';
1347
- }
1348
- return path.slice(0, end);
1349
- },
1350
-
1351
- basename(path: string, suffix?: string): string {
1352
- if (suffix !== undefined) {
1353
- validateString(suffix, 'suffix');
1354
- }
1355
- validateString(path, 'path');
1356
-
1357
- let start = 0;
1358
- let end = -1;
1359
- let matchedSlash = true;
1360
- let i;
1361
-
1362
- if (suffix !== undefined && suffix.length > 0 && suffix.length <= path.length) {
1363
- if (suffix === path) {
1364
- return '';
1365
- }
1366
- let extIdx = suffix.length - 1;
1367
- let firstNonSlashEnd = -1;
1368
- for (i = path.length - 1; i >= 0; --i) {
1369
- const code = path.charCodeAt(i);
1370
- if (code === CHAR_FORWARD_SLASH) {
1371
- // If we reached a path separator that was not part of a set of path
1372
- // separators at the end of the string, stop now
1373
- if (!matchedSlash) {
1374
- start = i + 1;
1375
- break;
1376
- }
1377
- } else {
1378
- if (firstNonSlashEnd === -1) {
1379
- // We saw the first non-path separator, remember this index in case
1380
- // we need it if the extension ends up not matching
1381
- matchedSlash = false;
1382
- firstNonSlashEnd = i + 1;
1383
- }
1384
- if (extIdx >= 0) {
1385
- // Try to match the explicit extension
1386
- if (code === suffix.charCodeAt(extIdx)) {
1387
- if (--extIdx === -1) {
1388
- // We matched the extension, so mark this as the end of our path
1389
- // component
1390
- end = i;
1391
- }
1392
- } else {
1393
- // Extension does not match, so our result is the entire path
1394
- // component
1395
- extIdx = -1;
1396
- end = firstNonSlashEnd;
1397
- }
1398
- }
1399
- }
1400
- }
1401
-
1402
- if (start === end) {
1403
- end = firstNonSlashEnd;
1404
- } else if (end === -1) {
1405
- end = path.length;
1406
- }
1407
- return path.slice(start, end);
1408
- }
1409
- for (i = path.length - 1; i >= 0; --i) {
1410
- if (path.charCodeAt(i) === CHAR_FORWARD_SLASH) {
1411
- // If we reached a path separator that was not part of a set of path
1412
- // separators at the end of the string, stop now
1413
- if (!matchedSlash) {
1414
- start = i + 1;
1415
- break;
1416
- }
1417
- } else if (end === -1) {
1418
- // We saw the first non-path separator, mark this as the end of our
1419
- // path component
1420
- matchedSlash = false;
1421
- end = i + 1;
1422
- }
1423
- }
1424
-
1425
- if (end === -1) {
1426
- return '';
1427
- }
1428
- return path.slice(start, end);
1429
- },
1430
-
1431
- extname(path: string): string {
1432
- validateString(path, 'path');
1433
- let startDot = -1;
1434
- let startPart = 0;
1435
- let end = -1;
1436
- let matchedSlash = true;
1437
- // Track the state of characters (if any) we see before our first dot and
1438
- // after any path separator we find
1439
- let preDotState = 0;
1440
- for (let i = path.length - 1; i >= 0; --i) {
1441
- const char = path[i];
1442
- if (char === '/') {
1443
- // If we reached a path separator that was not part of a set of path
1444
- // separators at the end of the string, stop now
1445
- if (!matchedSlash) {
1446
- startPart = i + 1;
1447
- break;
1448
- }
1449
- continue;
1450
- }
1451
- if (end === -1) {
1452
- // We saw the first non-path separator, mark this as the end of our
1453
- // extension
1454
- matchedSlash = false;
1455
- end = i + 1;
1456
- }
1457
- if (char === '.') {
1458
- // If this is our first dot, mark it as the start of our extension
1459
- if (startDot === -1) {
1460
- startDot = i;
1461
- }
1462
- else if (preDotState !== 1) {
1463
- preDotState = 1;
1464
- }
1465
- } else if (startDot !== -1) {
1466
- // We saw a non-dot and non-path separator before our dot, so we should
1467
- // have a good chance at having a non-empty extension
1468
- preDotState = -1;
1469
- }
1470
- }
1471
-
1472
- if (startDot === -1 ||
1473
- end === -1 ||
1474
- // We saw a non-dot character immediately before the dot
1475
- preDotState === 0 ||
1476
- // The (right-most) trimmed path component is exactly '..'
1477
- (preDotState === 1 &&
1478
- startDot === end - 1 &&
1479
- startDot === startPart + 1)) {
1480
- return '';
1481
- }
1482
- return path.slice(startDot, end);
1483
- },
1484
-
1485
- format: _format.bind(null, '/'),
1486
-
1487
- parse(path: string): ParsedPath {
1488
- validateString(path, 'path');
1489
-
1490
- const ret = { root: '', dir: '', base: '', ext: '', name: '' };
1491
- if (path.length === 0) {
1492
- return ret;
1493
- }
1494
- const isAbsolute = path.charCodeAt(0) === CHAR_FORWARD_SLASH;
1495
- let start;
1496
- if (isAbsolute) {
1497
- ret.root = '/';
1498
- start = 1;
1499
- } else {
1500
- start = 0;
1501
- }
1502
- let startDot = -1;
1503
- let startPart = 0;
1504
- let end = -1;
1505
- let matchedSlash = true;
1506
- let i = path.length - 1;
1507
-
1508
- // Track the state of characters (if any) we see before our first dot and
1509
- // after any path separator we find
1510
- let preDotState = 0;
1511
-
1512
- // Get non-dir info
1513
- for (; i >= start; --i) {
1514
- const code = path.charCodeAt(i);
1515
- if (code === CHAR_FORWARD_SLASH) {
1516
- // If we reached a path separator that was not part of a set of path
1517
- // separators at the end of the string, stop now
1518
- if (!matchedSlash) {
1519
- startPart = i + 1;
1520
- break;
1521
- }
1522
- continue;
1523
- }
1524
- if (end === -1) {
1525
- // We saw the first non-path separator, mark this as the end of our
1526
- // extension
1527
- matchedSlash = false;
1528
- end = i + 1;
1529
- }
1530
- if (code === CHAR_DOT) {
1531
- // If this is our first dot, mark it as the start of our extension
1532
- if (startDot === -1) {
1533
- startDot = i;
1534
- } else if (preDotState !== 1) {
1535
- preDotState = 1;
1536
- }
1537
- } else if (startDot !== -1) {
1538
- // We saw a non-dot and non-path separator before our dot, so we should
1539
- // have a good chance at having a non-empty extension
1540
- preDotState = -1;
1541
- }
1542
- }
1543
-
1544
- if (end !== -1) {
1545
- const start = startPart === 0 && isAbsolute ? 1 : startPart;
1546
- if (startDot === -1 ||
1547
- // We saw a non-dot character immediately before the dot
1548
- preDotState === 0 ||
1549
- // The (right-most) trimmed path component is exactly '..'
1550
- (preDotState === 1 &&
1551
- startDot === end - 1 &&
1552
- startDot === startPart + 1)) {
1553
- ret.base = ret.name = path.slice(start, end);
1554
- } else {
1555
- ret.name = path.slice(start, startDot);
1556
- ret.base = path.slice(start, end);
1557
- ret.ext = path.slice(startDot, end);
1558
- }
1559
- }
1560
-
1561
- if (startPart > 0) {
1562
- ret.dir = path.slice(0, startPart - 1);
1563
- } else if (isAbsolute) {
1564
- ret.dir = '/';
1565
- }
1566
-
1567
- return ret;
1568
- },
1569
-
1570
- sep: '/',
1571
- delimiter: ':',
1572
- win32: null,
1573
- posix: null
1574
- };
1575
-
1576
- posix.win32 = win32.win32 = win32;
1577
- posix.posix = win32.posix = posix;
1578
-
1579
- export const normalize = (platformIsWin32 ? win32.normalize : posix.normalize);
1580
- export const isAbsolute = (platformIsWin32 ? win32.isAbsolute : posix.isAbsolute);
1581
- export const join = (platformIsWin32 ? win32.join : posix.join);
1582
- export const resolve = (platformIsWin32 ? win32.resolve : posix.resolve);
1583
- export const relative = (platformIsWin32 ? win32.relative : posix.relative);
1584
- export const dirname = (platformIsWin32 ? win32.dirname : posix.dirname);
1585
- export const basename = (platformIsWin32 ? win32.basename : posix.basename);
1586
- export const extname = (platformIsWin32 ? win32.extname : posix.extname);
1587
- export const format = (platformIsWin32 ? win32.format : posix.format);
1588
- export const parse = (platformIsWin32 ? win32.parse : posix.parse);
1589
- export const toNamespacedPath = (platformIsWin32 ? win32.toNamespacedPath : posix.toNamespacedPath);
1590
- export const sep = (platformIsWin32 ? win32.sep : posix.sep);
1591
- export const delimiter = (platformIsWin32 ? win32.delimiter : posix.delimiter);