@ttsc/banner 0.38.0 → 0.38.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 (2) hide show
  1. package/driver/banner.go +10 -93
  2. package/package.json +2 -2
package/driver/banner.go CHANGED
@@ -5,7 +5,6 @@ import (
5
5
  "context"
6
6
  "crypto/sha256"
7
7
  "encoding/json"
8
- "errors"
9
8
  "fmt"
10
9
  "os"
11
10
  "os/exec"
@@ -13,11 +12,11 @@ import (
13
12
  "runtime"
14
13
  "strconv"
15
14
  "strings"
16
- "syscall"
17
15
 
18
16
  "github.com/samchon/ttsc/packages/ttsc/driver"
19
17
  "github.com/samchon/ttsc/packages/ttsc/driver/compileraliases"
20
18
  "github.com/samchon/ttsc/packages/ttsc/driver/configloaderscratch"
19
+ "github.com/samchon/ttsc/packages/ttsc/driver/packagemanifest"
21
20
  "github.com/samchon/ttsc/packages/ttsc/driver/resolutioninputs"
22
21
  "github.com/samchon/ttsc/packages/ttsc/driver/windowsjunction"
23
22
  )
@@ -581,6 +580,9 @@ func decodeBannerConfigLoaderOutput(output []byte) (bannerLoadedConfig, error) {
581
580
  // configToolAnchors. When TEMP is on another volume, an already-open identity
582
581
  // store can hold the loader without changing the config directory's metadata.
583
582
  func loadBannerTypeScriptConfigFileWithInputs(location, resolutionRoot string) (bannerLoadedConfig, error) {
583
+ if !filepath.IsAbs(location) {
584
+ return bannerLoadedConfig{}, fmt.Errorf("@ttsc/banner: resolve relative config import %s: expected an absolute config path", location)
585
+ }
584
586
  tempDir, err := createBannerConfigLoaderTempDir(location, os.TempDir(), os.Getenv("TTSC_NATIVE_PLUGIN_RECORD_ROOT"))
585
587
  if err != nil {
586
588
  return bannerLoadedConfig{}, fmt.Errorf("@ttsc/banner: create config loader tempdir: %w", err)
@@ -632,23 +634,11 @@ func loadBannerTypeScriptConfigFileWithInputs(location, resolutionRoot string) (
632
634
  return loaded, nil
633
635
  }
634
636
 
635
- // createBannerConfigLoaderTempDir uses this invocation's existing identity
636
- // directory when it is safe for the config; otherwise it preserves the
637
- // historical loader base. Expected filesystem refusal of the preferred base
638
- // also falls back, while unexpected errors remain visible to the caller.
637
+ // createBannerConfigLoaderTempDir creates the banner config loader's private
638
+ // scratch directory through the shared allocator, so every native config
639
+ // loader places its scratch by the same rule.
639
640
  func createBannerConfigLoaderTempDir(location, systemTemp, recordRoot string) (string, error) {
640
- preferred := configloaderscratch.IdentityTempBase(location, systemTemp, recordRoot)
641
- var tempDir string
642
- var err error
643
- if preferred != "" {
644
- tempDir, err = os.MkdirTemp(preferred, "ttsc-banner-config-")
645
- }
646
- if preferred == "" || (err != nil &&
647
- (os.IsPermission(err) || os.IsNotExist(err) ||
648
- errors.Is(err, syscall.ENOTDIR) || errors.Is(err, syscall.EROFS))) {
649
- tempDir, err = os.MkdirTemp(loaderTempBase(location, systemTemp), "ttsc-banner-config-")
650
- }
651
- return tempDir, err
641
+ return configloaderscratch.CreateLoaderTempDir(location, systemTemp, recordRoot, "ttsc-banner-config-")
652
642
  }
653
643
 
654
644
  // prepareBannerTypeScriptConfigLoader owns the ordered preparation needed before
@@ -855,46 +845,13 @@ func typeScriptConfigLoaderTsconfig(loader, location, outDir string) string {
855
845
  func configModuleOption(location string) string {
856
846
  switch strings.ToLower(filepath.Ext(location)) {
857
847
  case ".ts", ".tsx", ".js":
858
- if nearestPackageType(location) == "commonjs" {
848
+ if packagemanifest.NearestType(location) == "commonjs" {
859
849
  return "CommonJS"
860
850
  }
861
851
  }
862
852
  return "ESNext"
863
853
  }
864
854
 
865
- // nearestPackageType mirrors Node's package-scope lookup for the nearest
866
- // package.json above location: the walk stops at the FIRST manifest it finds,
867
- // and a manifest declaring no "type" means CommonJS rather than a reason to
868
- // keep climbing. Reaching the filesystem root without any manifest also means
869
- // CommonJS. The location is made absolute first, so a relative config path
870
- // cannot end the walk at "." after a single step.
871
- func nearestPackageType(location string) string {
872
- absolute, err := filepath.Abs(location)
873
- if err != nil {
874
- absolute = location
875
- }
876
- dir := filepath.Dir(absolute)
877
- for {
878
- raw, err := os.ReadFile(filepath.Join(dir, "package.json"))
879
- if err == nil {
880
- var manifest struct {
881
- Type string `json:"type"`
882
- }
883
- // A manifest that does not parse still bounds the package scope; Node
884
- // refuses to look past it, and CommonJS is the format it defaults to.
885
- if json.Unmarshal(raw, &manifest) == nil && manifest.Type == "module" {
886
- return "module"
887
- }
888
- return "commonjs"
889
- }
890
- parent := filepath.Dir(dir)
891
- if parent == dir {
892
- return "commonjs"
893
- }
894
- dir = parent
895
- }
896
- }
897
-
898
855
  // loaderRootDir returns the widest rootDir that still contains the loader
899
856
  // tsconfig's inputs: the volume root of the loader temp dir (`C:/` on
900
857
  // Windows, `/` elsewhere). A literal "/" is not an ancestor of drive-letter
@@ -909,46 +866,6 @@ func loaderRootDir(outDir string) string {
909
866
  return filepath.ToSlash(vol + `\`)
910
867
  }
911
868
 
912
- // loaderTempBase picks the parent directory for the ephemeral config-loader
913
- // tree. The system temp dir is the default, but when it sits on a different
914
- // volume than the config file (Windows: TEMP on `C:`, project on `D:`) the
915
- // loader cannot work from there — no single tsconfig rootDir spans two
916
- // volumes and filepath.Rel cannot produce a relative import across drives
917
- // (#305) — so the tree is created under the config's nearest
918
- // node_modules/.cache instead, falling back to the config's own directory
919
- // when no node_modules exists (or its .cache cannot be created): any location
920
- // on the config's volume beats the system temp dir, which is guaranteed to
921
- // fail. Returns "" (the os.MkdirTemp default) when the volumes already match.
922
- func loaderTempBase(location, systemTemp string) string {
923
- // A relative location has no volume; "" must not be read as "a volume
924
- // other than the system temp's" — it keeps the historical default (and
925
- // the Rel-failure contract for relative config paths).
926
- vol := filepath.VolumeName(location)
927
- if vol == "" || strings.EqualFold(filepath.VolumeName(systemTemp), vol) {
928
- return ""
929
- }
930
- nodeModules := findNearestNodeModules(filepath.Dir(location))
931
- if nodeModules == "" {
932
- return filepath.Dir(location)
933
- }
934
- // Resolve a linked node_modules (junction/symlink — common in managed
935
- // setups) before descending into it: the ESM runtime realpaths the loader
936
- // module at import time, and a relative config specifier computed from the
937
- // link-form path would resolve against the wrong directory. NTFS junctions
938
- // defeat filepath.EvalSymlinks, so the link component is chased by hand
939
- // first. Realpathing may also land on another volume, which defeats the
940
- // whole point — fall back to the config's directory then.
941
- base := filepath.Join(resolveDirLink(nodeModules), ".cache")
942
- if err := os.MkdirAll(base, 0o755); err != nil {
943
- return filepath.Dir(location)
944
- }
945
- real, err := filepath.EvalSymlinks(base)
946
- if err != nil || !strings.EqualFold(filepath.VolumeName(real), filepath.VolumeName(location)) {
947
- return filepath.Dir(location)
948
- }
949
- return real
950
- }
951
-
952
869
  // resolveDirLink chases a directory that is itself a symlink or NTFS junction
953
870
  // to its target (bounded against link cycles). os.Readlink is the probe:
954
871
  // it resolves junctions, which report neither ModeSymlink nor an
@@ -1075,7 +992,7 @@ func tsgoBinaryFrom(anchor string) string {
1075
992
  Name string `json:"name"`
1076
993
  Version string `json:"version"`
1077
994
  }
1078
- if err != nil || json.Unmarshal(body, &metadata) != nil {
995
+ if err != nil || packagemanifest.Unmarshal(body, &metadata) != nil {
1079
996
  return ""
1080
997
  }
1081
998
  major, err := strconv.Atoi(strings.SplitN(metadata.Version, ".", 2)[0])
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ttsc/banner",
3
- "version": "0.38.0",
3
+ "version": "0.38.2",
4
4
  "description": "First-party ttsc plugin that adds package-documentation JSDoc banners during emit.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -36,7 +36,7 @@
36
36
  "@types/node": "^25.3.0",
37
37
  "rimraf": "^6.1.2",
38
38
  "typescript": "^7.0.2",
39
- "ttsc": "0.38.0"
39
+ "ttsc": "0.38.2"
40
40
  },
41
41
  "repository": {
42
42
  "type": "git",