@rohal12/twee-ts 2.0.0 → 2.1.0
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.
- package/dist/bin/twee-ts.js +47 -32
- package/dist/bin/twee-ts.js.map +1 -1
- package/dist/{diagnostic-text-BRddVulf.cjs → diagnostic-text-Bj-UQ0Jl.cjs} +4283 -3739
- package/dist/diagnostic-text-Bj-UQ0Jl.cjs.map +1 -0
- package/dist/{diagnostic-text-CebYCTPQ.js → diagnostic-text-DMVZfBh9.js} +4260 -3770
- package/dist/diagnostic-text-DMVZfBh9.js.map +1 -0
- package/dist/index.cjs +4 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +3 -3
- package/dist/{lint-VayZI_jp.js → lint-BkpfLGuP.js} +3 -3
- package/dist/{lint-VayZI_jp.js.map → lint-BkpfLGuP.js.map} +1 -1
- package/dist/plugins/rollup.cjs +9 -4
- package/dist/plugins/rollup.cjs.map +1 -1
- package/dist/plugins/rollup.d.cts +6 -0
- package/dist/plugins/rollup.d.ts +6 -0
- package/dist/plugins/rollup.js +9 -4
- package/dist/plugins/rollup.js.map +1 -1
- package/dist/plugins/vite.cjs +453 -154
- package/dist/plugins/vite.cjs.map +1 -1
- package/dist/plugins/vite.js +453 -154
- package/dist/plugins/vite.js.map +1 -1
- package/dist/{watch-targets-C0Anuw17.cjs → watch-targets-BrEYmUwU.cjs} +84 -16
- package/dist/watch-targets-BrEYmUwU.cjs.map +1 -0
- package/dist/{watch-targets-BI7jYrwa.js → watch-targets-DzvPyWDo.js} +79 -17
- package/dist/watch-targets-DzvPyWDo.js.map +1 -0
- package/package.json +2 -2
- package/dist/diagnostic-text-BRddVulf.cjs.map +0 -1
- package/dist/diagnostic-text-CebYCTPQ.js.map +0 -1
- package/dist/watch-targets-BI7jYrwa.js.map +0 -1
- package/dist/watch-targets-C0Anuw17.cjs.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rollup.js","names":[],"sources":["../../src/plugins/link-watch.ts","../../src/plugins/rollup.ts"],"sourcesContent":["/**\n * Tells a bundler's build watch that a link the story's inputs are reached through was pointed elsewhere, when the\n * bundler's own watcher can't. Rollup's watcher (chokidar) follows a registered link and watches the file it leads to,\n * so replacing the link, or a hop of a chain of links, raises nothing. The link's folder is watched here instead (not\n * recursively, so what the build writes below it is not reported), and a change of any link starts a build the way an\n * edit of a registered file does: by touching a file the plugin has registered with the bundler.\n */\nimport { mkdtempSync, readlinkSync, rmSync, utimesSync, watch, writeFileSync } from 'node:fs';\nimport type { FSWatcher } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { dirname, join } from 'node:path';\n\n/** How long a burst of file system events settles before the links are read again (a link is replaced in two steps). */\nconst SETTLE_MS = 30;\n\nexport interface LinkWatch {\n /** The file to register with the bundler's watcher: written when a link changed, with the number of changes so far. */\n readonly signal: string;\n /** Watches `links` (platform paths) from now on, instead of the links watched before. */\n watch(links: readonly string[]): void;\n /** Stops watching and removes the signal file. */\n close(): void;\n}\n\n/** Where a link leads (as written), or nothing when it is no link or does not exist. */\nfunction destination(link: string): string | undefined {\n try {\n return readlinkSync(link);\n } catch {\n return undefined;\n }\n}\n\n/**\n * A watch of links that touches its signal file when one of them leads elsewhere, or appears or disappears. The watch\n * is a refinement of the build watch: without a temporary folder to write the signal file in (a missing or read-only\n * TMPDIR), there is none, and a retargeted link is read with the next build something else starts.\n */\nexport function createLinkWatch(): LinkWatch | undefined {\n let folder: string | undefined;\n let signal: string;\n try {\n folder = mkdtempSync(join(tmpdir(), 'twee-ts-links-'));\n signal = join(folder, 'changed');\n writeFileSync(signal, '');\n } catch {\n if (folder !== undefined) rmSync(folder, { recursive: true, force: true });\n return undefined;\n }\n const signalFolder = folder;\n let touches = 0;\n const watchers: FSWatcher[] = [];\n let timer: NodeJS.Timeout | undefined;\n let known = new Map<string, string | undefined>();\n\n const touch = (): void => {\n touches += 1;\n // A modification time that differs from every earlier one, whatever the clock's resolution.\n const at = new Date(Date.now() + touches * 1000);\n try {\n writeFileSync(signal, String(touches));\n utimesSync(signal, at, at);\n } catch {\n // The watch is closed.\n }\n };\n const check = (): void => {\n timer = undefined;\n const changed = [...known].filter(([link, was]) => destination(link) !== was);\n if (changed.length === 0) return;\n known = new Map([...known.keys()].map((link) => [link, destination(link)]));\n touch();\n };\n /** Reads the links again once the events that come together have come. */\n const schedule = (): void => {\n clearTimeout(timer);\n timer = setTimeout(check, SETTLE_MS);\n };\n const stopWatching = (): void => {\n for (const watcher of watchers.splice(0)) watcher.close();\n clearTimeout(timer);\n timer = undefined;\n };\n const onExit = (): void => {\n rmSync(signalFolder, { recursive: true, force: true });\n };\n process.once('exit', onExit);\n\n return {\n signal,\n watch(links) {\n stopWatching();\n known = new Map(links.map((link) => [link, destination(link)]));\n for (const parent of new Set(links.map((link) => dirname(link)))) {\n try {\n const watcher = watch(parent, schedule);\n // A folder that goes away, or a limit of the system: the links in it are read again.\n watcher.on('error', schedule);\n watchers.push(watcher);\n } catch {\n // The folder can't be watched; the links in it are read again with the next build.\n }\n }\n },\n close() {\n stopWatching();\n process.removeListener('exit', onExit);\n onExit();\n },\n };\n}\n","/**\n * Ready-made Rollup plugin for twee-ts.\n * Compiles .tw files and emits HTML as an asset. Compile errors fail the build\n * and emit nothing; warnings go through Rollup's warnings.\n */\nimport { resolve, sep } from 'node:path';\nimport { outputPaths } from '../filesystem.js';\nimport { compileStory, fatalError } from './diagnostics.js';\nimport type { CompiledStory, LocatedError } from './diagnostics.js';\nimport { resolvePluginOptions } from './options.js';\nimport type { SharedPluginOptions } from './options.js';\nimport { createOutputRecord, outputLocations } from './paths.js';\nimport type { OutputLocation } from './paths.js';\nimport { createLinkWatch } from './link-watch.js';\nimport type { LinkWatch } from './link-watch.js';\nimport { watchPlan } from './watch-targets.js';\n\nexport type { PluginCompileOptions } from './options.js';\n\nexport type TweeTsRollupPluginOptions = SharedPluginOptions;\n\nexport function tweeTsPlugin(options: TweeTsRollupPluginOptions) {\n const resolved = resolvePluginOptions('rollup', options);\n const { outputFilename } = resolved;\n // Every path this plugin's builds write: each output's folder or file, its story,\n // and the files of each bundle. A source folder may hold any of them, and none\n // may be read back as a source or rebuild under watch.\n const record = createOutputRecord(outputFilename);\n // Tells the watch that a link the inputs are reached through was pointed elsewhere (see link-watch.ts).\n let linkWatch: LinkWatch | undefined;\n // The link watch could not be set up (no temporary folder); said once, and not tried again.\n let linkWatchUnavailable = false;\n // Where each registered path led when Rollup's watcher first followed it.\n const followed = new Map<string, string>();\n\n return {\n name: 'twee-ts',\n\n // Rollup's watch mode and CLI pass the whole config here, outputs included, so\n // they are known before the first build starts and before any is written.\n // Typed `object`: a type with only optional properties would share none with\n // Rollup's InputOptions, and the plugin would no longer be assignable to Plugin.\n options(inputOptions: object): undefined {\n const output: unknown = Reflect.get(inputOptions, 'output');\n for (const location of outputLocations(output)) record.addLocation(location);\n return undefined;\n },\n\n // `rollup --watch` rebuilds for the files the build registers. The story's\n // inputs are read in generateBundle, outside the module graph, so they are\n // registered here: the sources, the head file and the modules, without the\n // files `exclude` leaves out (see watchTargets). Rollup's watcher follows a link and watches what it leads to, so\n // it doesn't see a link, or a hop of a chain of links, pointed elsewhere; the plugin watches the links itself.\n buildStart(this: {\n addWatchFile: (id: string) => void;\n warn: (message: string) => void;\n meta: { watchMode: boolean };\n }) {\n if (!this.meta.watchMode) return;\n const outputs = outputPaths(record.outputs());\n // In the platform's own form, as Rollup reports its module ids.\n const plan = watchPlan(resolved.inputs, resolved.excluded, outputs, 'given');\n const targets = plan.targets.map((target) => resolve(target));\n for (const target of targets) this.addWatchFile(target);\n // Rollup's watcher keeps watching what a path led to when it was registered, so a path that leads elsewhere now\n // (a link was pointed at another file or folder) is watched from its new location as well.\n for (const [path, real] of plan.reals) {\n const first = followed.get(path) ?? real;\n followed.set(path, first);\n if (first !== real) this.addWatchFile(resolve(real));\n }\n if (plan.links.length > 0 && !linkWatchUnavailable) {\n linkWatch ??= createLinkWatch();\n if (linkWatch === undefined) {\n // The links are a refinement: the build goes on, and says once what the watch cannot do.\n linkWatchUnavailable = true;\n this.warn(\n '[twee-ts] The link watch is unavailable because no temporary folder can be written (check TMPDIR); ' +\n 'a link pointed at another target is read with the next build something else starts.',\n );\n } else {\n linkWatch.watch(plan.links);\n this.addWatchFile(linkWatch.signal);\n }\n }\n // Rollup's file watcher (chokidar) reads every backslash as a separator, also on POSIX, where it is a\n // filename character: such a file is read by each build, but an edit to it starts none.\n const unwatchable = sep === '/' ? targets.filter((target) => target.includes('\\\\')) : [];\n if (unwatchable.length > 0) {\n this.warn(\n `[twee-ts] Rollup's watch mode cannot watch ${unwatchable.map((target) => JSON.stringify(target)).join(', ')} ` +\n 'because the name contains a backslash; edits to it will not rebuild the story.',\n );\n }\n },\n\n // The watcher is closed: the links are no longer watched.\n closeWatcher(): void {\n linkWatch?.close();\n linkWatch = undefined;\n },\n\n // Runs for every output before any of them generates its bundle, when the\n // outputs are written together (as the CLI and watch mode write them).\n renderStart(outputOptions: OutputLocation): void {\n record.addLocation(outputOptions);\n },\n\n async generateBundle(\n this: {\n emitFile: (opts: { type: 'asset'; fileName: string; source: string }) => void;\n error: (error: LocatedError | string) => never;\n warn: (message: string) => void;\n },\n outputOptions: OutputLocation,\n bundle: Readonly<Record<string, unknown>>,\n ): Promise<void> {\n if (Object.hasOwn(bundle, outputFilename)) {\n return this.error(\n `twee-ts: the bundle already holds a file named ${outputFilename}; set the plugin's outputFilename to another name.`,\n );\n }\n // Where this output writes the story and the bundle. A source folder may hold\n // them, or another output's, and no last build of them may be read back.\n record.addLocation(outputOptions);\n record.addFiles(outputOptions, Object.keys(bundle));\n let story: CompiledStory;\n try {\n story = await compileStory(resolved.compile(), record.outputs(), undefined, true);\n } catch (e) {\n return this.error(fatalError(e));\n }\n for (const warning of story.warnings) this.warn(warning);\n this.emitFile({ type: 'asset', fileName: outputFilename, source: story.output });\n },\n };\n}\n"],"mappings":";;;;;;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ells a bundler's build watch that a link the story's inputs are reached through was pointed elsewhere, when the\n * bundler's own watcher can't. Rollup's watcher (chokidar) follows a registered link and watches the file it leads to,\n * so replacing the link, or a hop of a chain of links, raises nothing. The link's folder is watched here instead (not\n * recursively, so what the build writes below it is not reported), and a change of any link starts a build the way an\n * edit of a registered file does: by touching a file the plugin has registered with the bundler.\n */\nimport { mkdtempSync, readlinkSync, rmSync, utimesSync, watch, writeFileSync } from 'node:fs';\nimport type { FSWatcher } from 'node:fs';\nimport { tmpdir } from 'node:os';\nimport { dirname, join } from 'node:path';\n\n/** How long a burst of file system events settles before the links are read again (a link is replaced in two steps). */\nconst SETTLE_MS = 30;\n\nexport interface LinkWatch {\n /** The file to register with the bundler's watcher: written when a link changed, with the number of changes so far. */\n readonly signal: string;\n /** Watches `links` (platform paths) from now on, instead of the links watched before. */\n watch(links: readonly string[]): void;\n /** Stops watching and removes the signal file. */\n close(): void;\n}\n\n/** Where a link leads (as written), or nothing when it is no link or does not exist. */\nfunction destination(link: string): string | undefined {\n try {\n return readlinkSync(link);\n } catch {\n return undefined;\n }\n}\n\n/**\n * A watch of links that touches its signal file when one of them leads elsewhere, or appears or disappears. The watch\n * is a refinement of the build watch: without a temporary folder to write the signal file in (a missing or read-only\n * TMPDIR), there is none, and a retargeted link is read with the next build something else starts.\n */\nexport function createLinkWatch(): LinkWatch | undefined {\n let folder: string | undefined;\n let signal: string;\n try {\n folder = mkdtempSync(join(tmpdir(), 'twee-ts-links-'));\n signal = join(folder, 'changed');\n writeFileSync(signal, '');\n } catch {\n if (folder !== undefined) rmSync(folder, { recursive: true, force: true });\n return undefined;\n }\n const signalFolder = folder;\n let touches = 0;\n const watchers: FSWatcher[] = [];\n let timer: NodeJS.Timeout | undefined;\n let known = new Map<string, string | undefined>();\n\n const touch = (): void => {\n touches += 1;\n // A modification time that differs from every earlier one, whatever the clock's resolution.\n const at = new Date(Date.now() + touches * 1000);\n try {\n writeFileSync(signal, String(touches));\n utimesSync(signal, at, at);\n } catch {\n // The watch is closed.\n }\n };\n const check = (): void => {\n timer = undefined;\n const changed = [...known].filter(([link, was]) => destination(link) !== was);\n if (changed.length === 0) return;\n known = new Map([...known.keys()].map((link) => [link, destination(link)]));\n touch();\n };\n /** Reads the links again once the events that come together have come. */\n const schedule = (): void => {\n clearTimeout(timer);\n timer = setTimeout(check, SETTLE_MS);\n };\n const stopWatching = (): void => {\n for (const watcher of watchers.splice(0)) watcher.close();\n clearTimeout(timer);\n timer = undefined;\n };\n const onExit = (): void => {\n rmSync(signalFolder, { recursive: true, force: true });\n };\n process.once('exit', onExit);\n\n return {\n signal,\n watch(links) {\n stopWatching();\n known = new Map(links.map((link) => [link, destination(link)]));\n for (const parent of new Set(links.map((link) => dirname(link)))) {\n try {\n const watcher = watch(parent, schedule);\n // A folder that goes away, or a limit of the system: the links in it are read again.\n watcher.on('error', schedule);\n watchers.push(watcher);\n } catch {\n // The folder can't be watched; the links in it are read again with the next build.\n }\n }\n },\n close() {\n stopWatching();\n process.removeListener('exit', onExit);\n onExit();\n },\n };\n}\n","/**\n * Ready-made Rollup plugin for twee-ts.\n * Compiles .tw files and emits HTML as an asset. Compile errors fail the build\n * and emit nothing; warnings go through Rollup's warnings.\n */\nimport { resolve, sep } from 'node:path';\nimport { outputPaths } from '../filesystem.js';\nimport { recordOwnOutput } from '../atomic-write.js';\nimport { compileStory, fatalError } from './diagnostics.js';\nimport type { CompiledStory, LocatedError } from './diagnostics.js';\nimport { resolvePluginOptions } from './options.js';\nimport type { SharedPluginOptions } from './options.js';\nimport { createOutputRecord, emittedFilePath, outputLocations } from './paths.js';\nimport type { OutputLocation } from './paths.js';\nimport { createLinkWatch } from './link-watch.js';\nimport type { LinkWatch } from './link-watch.js';\nimport { watchPlan } from './watch-targets.js';\nimport { identify } from '../path-identity.js';\n\nexport type { PluginCompileOptions } from './options.js';\n\nexport type TweeTsRollupPluginOptions = SharedPluginOptions;\n\nexport function tweeTsPlugin(options: TweeTsRollupPluginOptions) {\n const resolved = resolvePluginOptions('rollup', options);\n const { outputFilename } = resolved;\n // Every path this plugin's builds write: each output's folder or file, its story,\n // and the files of each bundle. A source folder may hold any of them, and none\n // may be read back as a source or rebuild under watch.\n const record = createOutputRecord(outputFilename);\n // Tells the watch that a link the inputs are reached through was pointed elsewhere (see link-watch.ts).\n let linkWatch: LinkWatch | undefined;\n // The link watch could not be set up (no temporary folder); said once, and not tried again.\n let linkWatchUnavailable = false;\n // Where each registered path led when Rollup's watcher first followed it.\n const followed = new Map<string, string>();\n\n return {\n name: 'twee-ts',\n\n // Rollup's watch mode and CLI pass the whole config here, outputs included, so\n // they are known before the first build starts and before any is written.\n // Typed `object`: a type with only optional properties would share none with\n // Rollup's InputOptions, and the plugin would no longer be assignable to Plugin.\n options(inputOptions: object): undefined {\n const output: unknown = Reflect.get(inputOptions, 'output');\n for (const location of outputLocations(output)) record.addLocation(location);\n return undefined;\n },\n\n // `rollup --watch` rebuilds for the files the build registers. The story's\n // inputs are read in generateBundle, outside the module graph, so they are\n // registered here: the sources, the head file and the modules, without the\n // files `exclude` leaves out (see watchTargets). Rollup's watcher follows a link and watches what it leads to, so\n // it doesn't see a link, or a hop of a chain of links, pointed elsewhere; the plugin watches the links itself.\n buildStart(this: {\n addWatchFile: (id: string) => void;\n warn: (message: string) => void;\n meta: { watchMode: boolean };\n }) {\n if (!this.meta.watchMode) return;\n const outputs = outputPaths(record.outputs(), 'snapshot');\n // In the platform's own form, as Rollup reports its module ids.\n const plan = watchPlan(resolved.inputs, resolved.excluded, outputs, 'given');\n const targets = plan.targets.map((target) => identify(target).absolute);\n for (const target of targets) this.addWatchFile(target);\n // Rollup's watcher keeps watching what a path led to when it was registered, so a path that leads elsewhere now\n // (a link was pointed at another file or folder) is watched from its new location as well.\n for (const [path, real] of plan.reals) {\n const first = followed.get(path) ?? real;\n followed.set(path, first);\n if (first !== real) this.addWatchFile(resolve(real));\n }\n if (plan.links.length > 0 && !linkWatchUnavailable) {\n linkWatch ??= createLinkWatch();\n if (linkWatch === undefined) {\n // The links are a refinement: the build goes on, and says once what the watch cannot do.\n linkWatchUnavailable = true;\n this.warn(\n '[twee-ts] The link watch is unavailable because no temporary folder can be written (check TMPDIR); ' +\n 'a link pointed at another target is read with the next build something else starts.',\n );\n } else {\n linkWatch.watch(plan.links);\n this.addWatchFile(linkWatch.signal);\n }\n }\n // Rollup's file watcher (chokidar) reads every backslash as a separator, also on POSIX, where it is a\n // filename character: such a file is read by each build, but an edit to it starts none.\n const unwatchable = sep === '/' ? targets.filter((target) => target.includes('\\\\')) : [];\n if (unwatchable.length > 0) {\n this.warn(\n `[twee-ts] Rollup's watch mode cannot watch ${unwatchable.map((target) => JSON.stringify(target)).join(', ')} ` +\n 'because the name contains a backslash; edits to it will not rebuild the story.',\n );\n }\n },\n\n // The watcher is closed: the links are no longer watched.\n closeWatcher(): void {\n linkWatch?.close();\n linkWatch = undefined;\n },\n\n // Runs for every output before any of them generates its bundle, when the\n // outputs are written together (as the CLI and watch mode write them).\n renderStart(outputOptions: OutputLocation): void {\n record.addLocation(outputOptions);\n },\n\n async generateBundle(\n this: {\n emitFile: (opts: { type: 'asset'; fileName: string; source: string }) => void;\n error: (error: LocatedError | string) => never;\n warn: (message: string) => void;\n },\n outputOptions: OutputLocation,\n bundle: Readonly<Record<string, unknown>>,\n ): Promise<void> {\n if (Object.hasOwn(bundle, outputFilename)) {\n return this.error(\n `twee-ts: the bundle already holds a file named ${outputFilename}; set the plugin's outputFilename to another name.`,\n );\n }\n // Where this output writes the story and the bundle. A source folder may hold\n // them, or another output's, and no last build of them may be read back.\n record.addLocation(outputOptions);\n record.addFiles(outputOptions, Object.keys(bundle));\n let story: CompiledStory;\n try {\n story = await compileStory(resolved.compile(), record.outputs(), undefined, true);\n } catch (e) {\n return this.error(fatalError(e));\n }\n for (const warning of story.warnings) this.warn(warning);\n this.emitFile({ type: 'asset', fileName: outputFilename, source: story.output });\n },\n\n writeBundle(\n outputOptions: OutputLocation,\n bundle: Readonly<\n Record<string, { readonly type: 'asset'; readonly source: string | Uint8Array } | { readonly type: 'chunk' }>\n >,\n ): void {\n const asset = bundle[outputFilename];\n const destination = emittedFilePath(outputOptions, outputFilename);\n // Rollup writes the asset itself. Only a completed write establishes ownership, including for output\n // modes without creator markers; generate() must leave the ownership of existing disk bytes unchanged.\n if (asset?.type === 'asset' && destination !== undefined) recordOwnOutput(destination, asset.source);\n },\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;AAaA,MAAM,YAAY;;AAYlB,SAAS,YAAY,MAAkC;CACrD,IAAI;EACF,OAAO,aAAa,IAAI;CAC1B,QAAQ;EACN;CACF;AACF;;;;;;AAOA,SAAgB,kBAAyC;CACvD,IAAI;CACJ,IAAI;CACJ,IAAI;EACF,SAAS,YAAY,KAAK,OAAO,GAAG,gBAAgB,CAAC;EACrD,SAAS,KAAK,QAAQ,SAAS;EAC/B,cAAc,QAAQ,EAAE;CAC1B,QAAQ;EACN,IAAI,WAAW,KAAA,GAAW,OAAO,QAAQ;GAAE,WAAW;GAAM,OAAO;EAAK,CAAC;EACzE;CACF;CACA,MAAM,eAAe;CACrB,IAAI,UAAU;CACd,MAAM,WAAwB,CAAC;CAC/B,IAAI;CACJ,IAAI,wBAAQ,IAAI,IAAgC;CAEhD,MAAM,cAAoB;EACxB,WAAW;EAEX,MAAM,KAAK,IAAI,KAAK,KAAK,IAAI,IAAI,UAAU,GAAI;EAC/C,IAAI;GACF,cAAc,QAAQ,OAAO,OAAO,CAAC;GACrC,WAAW,QAAQ,IAAI,EAAE;EAC3B,QAAQ,CAER;CACF;CACA,MAAM,cAAoB;EACxB,QAAQ,KAAA;EAER,IADgB,CAAC,GAAG,KAAK,CAAC,CAAC,QAAQ,CAAC,MAAM,SAAS,YAAY,IAAI,MAAM,GAC/D,CAAC,CAAC,WAAW,GAAG;EAC1B,QAAQ,IAAI,IAAI,CAAC,GAAG,MAAM,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,MAAM,YAAY,IAAI,CAAC,CAAC,CAAC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